Add exported function to create HTTPError

This can be used by backends to influence the status code returned to
clients for errors that occurred in the backend.
This commit is contained in:
Conrad Hoffmann 2022-05-03 16:50:28 +02:00 committed by Simon Ser
parent 95a4ae783b
commit b5c6f8927c

View File

@ -40,6 +40,15 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hh.ServeHTTP(w, r) hh.ServeHTTP(w, r)
} }
// NewHTTPError creates a new error that is associated with an HTTP status code
// and optionally an error that lead to it. Backends can use this functions to
// return errors that convey some semantics (e.g. 404 not found, 403 access
// denied, etc) while also providing an (optional) arbitrary error context
// (intended for humans).
func NewHTTPError(statusCode int, cause error) error {
return &internal.HTTPError{Code: statusCode, Err: cause}
}
type backend struct { type backend struct {
FileSystem FileSystem FileSystem FileSystem
} }