Documentation
¶
Overview ¶
Package errs defines the error values handlers return. A central handler (see package web) turns them into HTML pages, redirects with flashed errors, HTMX fragments or RFC 9457 problem details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadRequest = &HTTPError{Status: http.StatusBadRequest} ErrForbidden = &HTTPError{Status: http.StatusForbidden} ErrNotFound = &HTTPError{Status: http.StatusNotFound} ErrMethodNotAllowed = &HTTPError{Status: http.StatusMethodNotAllowed} ErrConflict = &HTTPError{Status: http.StatusConflict} ErrPreconditionFailed = &HTTPError{Status: http.StatusPreconditionFailed} ErrRequestTooLarge = &HTTPError{Status: http.StatusRequestEntityTooLarge} ErrUnsupportedMediaType = &HTTPError{Status: http.StatusUnsupportedMediaType} ErrUnprocessable = &HTTPError{Status: http.StatusUnprocessableEntity} ErrTooManyRequests = &HTTPError{Status: http.StatusTooManyRequests} ErrInternal = &HTTPError{Status: http.StatusInternalServerError} )
Sentinel errors for common statuses. Compare with errors.Is.
Functions ¶
Types ¶
type HTTPError ¶
type HTTPError struct {
// Status is the HTTP status code.
Status int
// Message is safe to show to clients. Empty means the status text.
Message string
// Err is the internal cause; it is logged, never shown to clients.
Err error
// Headers are added to the response (e.g. Allow, Retry-After).
Headers http.Header
}
HTTPError is an error with an HTTP status and a client-safe message.
func (*HTTPError) Is ¶
Is matches another *HTTPError with the same status, so sentinel errors work with errors.Is even when wrapped or re-created with a cause.
func (*HTTPError) WithHeader ¶
WithHeader returns a copy of e with an extra response header.
type StatusCoder ¶
StatusCoder is implemented by errors that carry their own HTTP status, such as errors from packages that should not import errs.
type ValidationError ¶
ValidationError reports invalid input, keyed by field path.
func NewValidation ¶
func NewValidation() *ValidationError
NewValidation returns an empty ValidationError.
func (*ValidationError) Add ¶
func (e *ValidationError) Add(field, message string) *ValidationError
Add appends a message for field.
func (*ValidationError) Empty ¶
func (e *ValidationError) Empty() bool
Empty reports whether no field has errors.
func (*ValidationError) First ¶
func (e *ValidationError) First(field string) string
First returns the first message for field, or "".