Documentation ¶
Overview ¶
Package httperrors defines an error wrapper that carries extra data for convenient rendering of errors in HTTP responses, esp. in JSON APIs.
Index ¶
- Constants
- Variables
- func ErrorID(err error) string
- func HTTPCode(err error) int
- func HTTPMessage(err error) string
- func Is4xx(err error) bool
- func Is5xx(err error) bool
- func String(err error, keys ...string) string
- func Value(err error, key string) interface{}
- type BaseError
- func (base BaseError) Error() string
- func (base BaseError) ErrorID() string
- func (base BaseError) Extra(k string, v interface{}) *Error
- func (base BaseError) ForeachExtra(f func(k string, v interface{}))
- func (base BaseError) HTTPCode() int
- func (base BaseError) Is(err error) bool
- func (base BaseError) Msg(pubmsg string) *Error
- func (base BaseError) Msgf(format string, args ...any) *Error
- func (base BaseError) PublicError() string
- func (base BaseError) String() string
- func (base BaseError) Wrap(cause error) Interface
- func (base BaseError) WrapCustom(prototype, cause error) *Error
- func (base BaseError) WrapMsg(cause error, pubmsg string) Interface
- type Error
- func (err *Error) Error() string
- func (err *Error) ErrorID() string
- func (err *Error) Extra(k string, v interface{}) *Error
- func (err *Error) ForeachExtra(f func(k string, v interface{}))
- func (err *Error) HTTPCode() int
- func (err *Error) Is(e error) bool
- func (err *Error) Msg(pubmsg string) *Error
- func (err *Error) Msgf(format string, args ...any) *Error
- func (err *Error) PublicError() string
- func (err *Error) String() string
- func (err *Error) Unwrap() error
- type Interface
- type PublicMessenger
Constants ¶
View Source
const ( HTTPCodeKey = "HTTPCode" PublicErrorKey = "PublicError" ErrorIDKey = "ErrorID" )
Variables ¶
View Source
var ( Define(http.StatusInternalServerError, "unavail") /* Overload signals expected temporary unavailability of the endpoint due to excessive requests or quota violation (HTTP 503 Service Unavailable). An appropriate client behavior is to retry with increasing backoff. */ Overload = Define(http.StatusServiceUnavailable, "unavail") /* BadRequest signals a wildly incorrect HTTP call that uses invalid parameter names, omits required parameters, uses invalid format for parameter values (e.g. a string passed for an integer parameter) or uses an unsupported value for a enumerated parameter. This should NOT be used for merely invalid data that likely comes from the user. Please define an appropriate error value for that. An appropriate client behavior is to log an error and fail the operation with a generic error message asking to contact support. */ BadRequest = Define(http.StatusBadRequest, "bad_request") /* NotFound signals a that the resource that the HTTP call primarily refers to does not exist. E.g. you're trying to update a page that does not exist. This should NOT be used for non-existent auxiliary data. For example, trying to save an article with a non-existent author should return a validation error (which you should define), not NotFound. Similarly, an unknown user account on a normal API endpoint should return an appropriate authentication error, not NotFound. An appropriate client behavior is to remove the UI corresponding to the data that this API call operates on. */ NotFound = Define(http.StatusNotFound, "not_found") /* MethodNotAllowed signals a wildly incorrect HTTP call, caused by using a mismatched HTTP verb. An appropriate client behavior is to log an error and fail the operation with a generic error message asking to contact support. */ MethodNotAllowed = Define(http.StatusMethodNotAllowed, "bad_request") )Unavailable =
Functions ¶
func HTTPMessage ¶
Types ¶
type BaseError ¶
type BaseError struct {
// contains filtered or unexported fields
}
func (BaseError) ForeachExtra ¶
func (BaseError) PublicError ¶
func (BaseError) WrapCustom ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func (*Error) ForeachExtra ¶
func (*Error) PublicError ¶
type Interface ¶
type PublicMessenger ¶ added in v0.2.2
type PublicMessenger interface {
PublicError() string
}
Click to show internal directories.
Click to hide internal directories.