1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 func Errorf(status int, tmpl string, args ...interface{}) error {
14 return errorWithStatus{fmt.Errorf(tmpl, args...), status}
17 func ErrorWithStatus(err error, status int) error {
18 return errorWithStatus{err, status}
21 type errorWithStatus struct {
26 func (ews errorWithStatus) HTTPStatus() int {
30 type ErrorResponse struct {
31 Errors []string `json:"errors"`
34 func Error(w http.ResponseWriter, error string, code int) {
35 Errors(w, []string{error}, code)
38 func Errors(w http.ResponseWriter, errors []string, code int) {
39 w.Header().Set("Content-Type", "application/json")
40 w.Header().Set("X-Content-Type-Options", "nosniff")
42 json.NewEncoder(w).Encode(ErrorResponse{Errors: errors})