18681: Fix typo
[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 func ErrorWithStatus(err error, status int) error {
13         return errorWithStatus{err, status}
14 }
15
16 type errorWithStatus struct {
17         error
18         Status int
19 }
20
21 func (ews errorWithStatus) HTTPStatus() int {
22         return ews.Status
23 }
24
25 type ErrorResponse struct {
26         Errors []string `json:"errors"`
27 }
28
29 func Error(w http.ResponseWriter, error string, code int) {
30         Errors(w, []string{error}, code)
31 }
32
33 func Errors(w http.ResponseWriter, errors []string, code int) {
34         w.Header().Set("Content-Type", "application/json")
35         w.Header().Set("X-Content-Type-Options", "nosniff")
36         w.WriteHeader(code)
37         json.NewEncoder(w).Encode(ErrorResponse{Errors: errors})
38 }