Documentation ¶
Index ¶
- Constants
- func Assertf(cond bool, format string, options ...Option)
- func Errorf(format string, options ...Option) error
- func FormatStackTrace(callers []uintptr) []string
- func GetCallers(err error) []uintptr
- func IgnoreClose(c io.Closer)
- func MaybeMustWrap(err error, options ...Option)
- func MaybeWrap(err error, options ...Option) error
- func MaybeWrapRecover(r interface{}, options ...Option) error
- func MustErrorf(format string, options ...Option)
- func MustWrap(err error, options ...Option)
- func Safe(f func() error) func() error
- func Unwrap(err error) error
- func Wrap(err error, options ...Option) error
- func WrapRecover(r interface{}, options ...Option) error
- type Args
- type ErrorResponse
- type ID
- type Metadata
- type Option
- type OptionFunc
- type StatusCode
Constants ¶
const ( StatusContinue = StatusCode(http.StatusContinue) StatusSwitchingProtocols = StatusCode(http.StatusSwitchingProtocols) StatusProcessing = StatusCode(http.StatusProcessing) StatusEarlyHints = StatusCode(http.StatusEarlyHints) StatusOK = StatusCode(http.StatusOK) StatusCreated = StatusCode(http.StatusCreated) StatusAccepted = StatusCode(http.StatusAccepted) StatusNonAuthoritativeInfo = StatusCode(http.StatusNonAuthoritativeInfo) StatusNoContent = StatusCode(http.StatusNoContent) StatusResetContent = StatusCode(http.StatusResetContent) StatusPartialContent = StatusCode(http.StatusPartialContent) StatusMultiStatus = StatusCode(http.StatusMultiStatus) StatusAlreadyReported = StatusCode(http.StatusAlreadyReported) StatusIMUsed = StatusCode(http.StatusIMUsed) StatusMultipleChoices = StatusCode(http.StatusMultipleChoices) StatusMovedPermanently = StatusCode(http.StatusMovedPermanently) StatusFound = StatusCode(http.StatusFound) StatusSeeOther = StatusCode(http.StatusSeeOther) StatusNotModified = StatusCode(http.StatusNotModified) StatusUseProxy = StatusCode(http.StatusUseProxy) StatusTemporaryRedirect = StatusCode(http.StatusTemporaryRedirect) StatusPermanentRedirect = StatusCode(http.StatusPermanentRedirect) StatusBadRequest = StatusCode(http.StatusBadRequest) StatusPaymentRequired = StatusCode(http.StatusPaymentRequired) StatusForbidden = StatusCode(http.StatusForbidden) StatusNotFound = StatusCode(http.StatusNotFound) StatusMethodNotAllowed = StatusCode(http.StatusMethodNotAllowed) StatusNotAcceptable = StatusCode(http.StatusNotAcceptable) StatusProxyAuthRequired = StatusCode(http.StatusProxyAuthRequired) StatusRequestTimeout = StatusCode(http.StatusRequestTimeout) StatusConflict = StatusCode(http.StatusConflict) StatusGone = StatusCode(http.StatusGone) StatusLengthRequired = StatusCode(http.StatusLengthRequired) StatusPreconditionFailed = StatusCode(http.StatusPreconditionFailed) StatusRequestEntityTooLarge = StatusCode(http.StatusRequestEntityTooLarge) StatusRequestURITooLong = StatusCode(http.StatusRequestURITooLong) StatusUnsupportedMediaType = StatusCode(http.StatusUnsupportedMediaType) StatusRequestedRangeNotSatisfiable = StatusCode(http.StatusRequestedRangeNotSatisfiable) StatusExpectationFailed = StatusCode(http.StatusExpectationFailed) StatusTeapot = StatusCode(http.StatusTeapot) StatusMisdirectedRequest = StatusCode(http.StatusMisdirectedRequest) StatusUnprocessableEntity = StatusCode(http.StatusUnprocessableEntity) StatusLocked = StatusCode(http.StatusLocked) StatusFailedDependency = StatusCode(http.StatusFailedDependency) StatusTooEarly = StatusCode(http.StatusTooEarly) StatusUpgradeRequired = StatusCode(http.StatusUpgradeRequired) StatusPreconditionRequired = StatusCode(http.StatusPreconditionRequired) StatusTooManyRequests = StatusCode(http.StatusTooManyRequests) StatusRequestHeaderFieldsTooLarge = StatusCode(http.StatusRequestHeaderFieldsTooLarge) StatusInternalServerError = StatusCode(http.StatusInternalServerError) StatusNotImplemented = StatusCode(http.StatusNotImplemented) StatusBadGateway = StatusCode(http.StatusBadGateway) StatusGatewayTimeout = StatusCode(http.StatusGatewayTimeout) StatusHTTPVersionNotSupported = StatusCode(http.StatusHTTPVersionNotSupported) StatusVariantAlsoNegotiates = StatusCode(http.StatusVariantAlsoNegotiates) StatusInsufficientStorage = StatusCode(http.StatusInsufficientStorage) StatusLoopDetected = StatusCode(http.StatusLoopDetected) StatusNotExtended = StatusCode(http.StatusNotExtended) StatusNetworkAuthenticationRequired = StatusCode(http.StatusNetworkAuthenticationRequired) )
Known status codes.
Variables ¶
This section is empty.
Functions ¶
func Errorf ¶
Errorf formats a new error and wraps it. Note: arguments implementing Option are applied on wrapping, the others are passed to fmt.Errorf().
func FormatStackTrace ¶
FormatStackTrace formats the given raw stack trace.
func GetCallers ¶
GetCallers returns the raw stack trace from the error, or the current raw stack trace if not found.
func IgnoreClose ¶
IgnoreClose calls Close on the given io.Closer, ignoring the returned error. Handy for the defer Close pattern.
func MaybeMustWrap ¶
MaybeMustWrap is like MustWrap, but does nothing if called with a nil error.
func MaybeWrapRecover ¶
MaybeWrapRecover is like WrapRecover but returns nil if called with a nil recover.
func MustErrorf ¶
MustErrorf is like Errorf but panics instead of returning the error.
func WrapRecover ¶
WrapRecover takes a recovered interface{} and converts it to a wrapped error.
Types ¶
type Args ¶
type Args []interface{}
Args describes a list of args used for formatting an error message.
type ErrorResponse ¶
type ErrorResponse struct { ErrorID ID `json:"errorId,omitempty"` StatusCode StatusCode `json:"statusCode,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` Message string `json:"message,omitempty"` StackTrace []string `json:"stackTrace,omitempty"` }
ErrorResponse describes an error response.
func ToResponse ¶
func ToResponse(err error) *ErrorResponse
ToResponse converts an error to ErrorResponse.
type Metadata ¶
type Metadata map[string]interface{}
Metadata describes metadata which can be attached to errors.
func GetMetadata ¶
GetMetadata gets the metadata from the error, nil if not found.
type Option ¶
type Option interface {
Apply(err error)
}
Option describes an option which can be applied to an error.
type OptionFunc ¶
type OptionFunc func(err error)
OptionFunc describes an option which can be applied to an error.
func M ¶
func M(k string, v interface{}) OptionFunc
M is a shorthand for providing metadata to errors.
func Prefix ¶
func Prefix(format string, a ...interface{}) OptionFunc
Prefix adds a prefix to the error message.
func (OptionFunc) Apply ¶
func (f OptionFunc) Apply(err error)
Apply implements the Option interface.
type StatusCode ¶
type StatusCode int
StatusCode describes an HTTP status code.
func GetStatusCode ¶
func GetStatusCode(err error) StatusCode
GetStatusCode gets the status code from the error, or 0 if not set.
func GetStatusCodeOr500 ¶
func GetStatusCodeOr500(err error) StatusCode
GetStatusCodeOr500 gets the status code from the error, or InternalServerError if not set.
func (StatusCode) Apply ¶
func (s StatusCode) Apply(err error)
Apply implements the Option interface.
func (StatusCode) In ¶
func (s StatusCode) In(err error) bool
In returns true if the given error has this status code.
func (StatusCode) String ¶
func (s StatusCode) String() string
String implements the fmt.Stringer interface.