Merge branch '15209-python-arv-deps-pinned'
[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         Errors(w, []string{error}, code)
18 }
19
20 func Errors(w http.ResponseWriter, errors []string, code int) {
21         w.Header().Set("Content-Type", "application/json")
22         w.Header().Set("X-Content-Type-Options", "nosniff")
23         w.WriteHeader(code)
24         json.NewEncoder(w).Encode(ErrorResponse{Errors: errors})
25 }