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