X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/473029212de9517dc2c486122cee7c9ca4c47ad5..1166aeb6033725709ded753a0c00f69320a9a873:/sdk/go/httpserver/error.go diff --git a/sdk/go/httpserver/error.go b/sdk/go/httpserver/error.go index 1ccf8c0478..f1817d3374 100644 --- a/sdk/go/httpserver/error.go +++ b/sdk/go/httpserver/error.go @@ -9,15 +9,25 @@ import ( "net/http" ) +func ErrorWithStatus(err error, status int) error { + return errorWithStatus{err, status} +} + +type errorWithStatus struct { + error + Status int +} + +func (ews errorWithStatus) HTTPStatus() int { + return ews.Status +} + type ErrorResponse struct { Errors []string `json:"errors"` } func Error(w http.ResponseWriter, error string, code int) { - w.Header().Set("Content-Type", "application/json") - w.Header().Set("X-Content-Type-Options", "nosniff") - w.WriteHeader(code) - json.NewEncoder(w).Encode(ErrorResponse{Errors: []string{error}}) + Errors(w, []string{error}, code) } func Errors(w http.ResponseWriter, errors []string, code int) {