Merge branch '13879-arvados-server' closes #13879
[arvados.git] / sdk / go / httpserver / error.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package httpserver
6
7 import (
8         "encoding/json"
9         "net/http"
10 )
11
12 type ErrorResponse struct {
13         Errors []string `json:"errors"`
14 }
15
16 func Error(w http.ResponseWriter, error string, code int) {
17         w.Header().Set("Content-Type", "application/json")
18         w.Header().Set("X-Content-Type-Options", "nosniff")
19         w.WriteHeader(code)
20         json.NewEncoder(w).Encode(ErrorResponse{Errors: []string{error}})
21 }