Documentation
¶
Index ¶
- func AddDetails(err error, details interface{}) error
- func As(err error, target interface{}) bool
- func Errorf(msg string, args ...interface{}) error
- func GetDetails(err error) []interface{}
- func GetStackTrace(err error) string
- func GetUserMessage(err error) string
- func Is(err error, target error) bool
- func SetUserMessage(err error, msg string) error
- func UserErrorf(msg string, args ...interface{}) error
- func UserWrapf(err error, msg string, args ...interface{}) error
- func Wrapf(err error, msg string, args ...interface{}) error
- type ErrorType
- func (errorType ErrorType) AddDetails(err error, details interface{}) error
- func (errorType ErrorType) Errorf(msg string, args ...interface{}) error
- func (errorType ErrorType) Set(err error) error
- func (errorType ErrorType) SetUserMessage(err error, msg string) error
- func (errorType ErrorType) UserErrorf(msg string, args ...interface{}) error
- func (errorType ErrorType) UserWrapf(err error, msg string, args ...interface{}) error
- func (errorType ErrorType) Wrapf(err error, msg string, args ...interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddDetails ¶ added in v0.5.0
AddDetails adds arbitrary details to an error.
func As ¶ added in v0.7.0
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false.
func GetDetails ¶ added in v0.5.0
func GetDetails(err error) []interface{}
GetDetails returns a slice of arbitrary details for all errors. If error is not `errorDetailer` returns nil.
func GetStackTrace ¶
GetStackTrace returns the stack trace starting from the first error that has been wrapped / created
func GetUserMessage ¶
GetUserMessage returns user readable error message for all errors. If error is not `userMessager` returns empty string.
func Is ¶ added in v0.8.0
Is finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false.
func SetUserMessage ¶ added in v0.6.0
SetUserMessage sets the user message to an error
func UserErrorf ¶
UserErrorf returns an error with formatted user message.
Types ¶
type ErrorType ¶
type ErrorType uint
ErrorType is the type of an error
const ( // NoType error - Default placeholder for un-typed errors. // Methods on NoType behave differently than other types - they // will preserve an existing type when wrapping a typed error. NoType ErrorType = iota // BadRequest error - Code 400 BadRequest ErrorType = http.StatusBadRequest Unauthorized ErrorType = http.StatusUnauthorized // PaymentRequired error - Code 402 PaymentRequired ErrorType = http.StatusPaymentRequired // Forbidden error - Code 403 Forbidden ErrorType = http.StatusForbidden // NotFound error - Code 404 NotFound ErrorType = http.StatusNotFound // MethodNotAllowed error - Code 405 MethodNotAllowed ErrorType = http.StatusMethodNotAllowed // NotAcceptable error - Code 406 NotAcceptable ErrorType = http.StatusNotAcceptable // ProxyAuthRequired error - Code 407 ProxyAuthRequired ErrorType = http.StatusProxyAuthRequired // RequestTimeout error - Code 408 RequestTimeout ErrorType = http.StatusRequestTimeout // Conflict error - Code 409 Conflict ErrorType = http.StatusConflict // Gone error - Code 410 Gone ErrorType = http.StatusGone // LengthRequired error - Code 411 LengthRequired ErrorType = http.StatusLengthRequired // PreconditionFailed error - Code 412 PreconditionFailed ErrorType = http.StatusPreconditionFailed // RequestEntityTooLarge error - Code 413 RequestEntityTooLarge ErrorType = http.StatusRequestEntityTooLarge // RequestURITooLong error - Code 414 RequestURITooLong ErrorType = http.StatusRequestURITooLong // UnsupportedMediaType error - Code 415 UnsupportedMediaType ErrorType = http.StatusUnsupportedMediaType // RequestedRangeNotSatisfiable error - Code 416 RequestedRangeNotSatisfiable ErrorType = http.StatusRequestedRangeNotSatisfiable // ExpectationFailed error - Code 417 ExpectationFailed ErrorType = http.StatusExpectationFailed // Teapot error - Code 418 Teapot ErrorType = http.StatusTeapot // UnprocessableEntity error - Code 422 UnprocessableEntity ErrorType = http.StatusUnprocessableEntity // Locked error - Code 423 Locked ErrorType = http.StatusLocked // FailedDependency error - Code 424 FailedDependency ErrorType = http.StatusFailedDependency // UpgradeRequired error - Code 426 UpgradeRequired ErrorType = http.StatusUpgradeRequired // PreconditionRequired error - Code 428 PreconditionRequired ErrorType = http.StatusPreconditionRequired // TooManyRequests error - Code 429 TooManyRequests ErrorType = http.StatusTooManyRequests // RequestHeaderFieldsTooLarge error - Code 431 RequestHeaderFieldsTooLarge ErrorType = http.StatusRequestHeaderFieldsTooLarge UnavailableForLegalReasons ErrorType = http.StatusUnavailableForLegalReasons // InternalServerError error - Code 500 InternalServerError ErrorType = http.StatusInternalServerError // NotImplemented error - Code 501 NotImplemented ErrorType = http.StatusNotImplemented // BadGateway error - Code 502 BadGateway ErrorType = http.StatusBadGateway ServiceUnavailable ErrorType = http.StatusServiceUnavailable // GatewayTimeout error - Code 504 GatewayTimeout ErrorType = http.StatusGatewayTimeout // HTTPVersionNotSupported error - Code 505 HTTPVersionNotSupported ErrorType = http.StatusHTTPVersionNotSupported // VariantAlsoNegotiates error - Code 506 VariantAlsoNegotiates ErrorType = http.StatusVariantAlsoNegotiates // InsufficientStorage error - Code 507 InsufficientStorage ErrorType = http.StatusInsufficientStorage // LoopDetected error - Code 508 LoopDetected ErrorType = http.StatusLoopDetected // NotExtended error - Code 510 NotExtended ErrorType = http.StatusNotExtended // NetworkAuthenticationRequired error - Code 511 NetworkAuthenticationRequired ErrorType = http.StatusNetworkAuthenticationRequired )
func GetType ¶
GetType returns the error type for all errors. If error is not `typed` - it returns NoType.
func (ErrorType) AddDetails ¶ added in v0.5.0
AddDetails adds a details element to an error. Also sets error type (or preserves existing type if called on NoType).
func (ErrorType) SetUserMessage ¶ added in v0.6.0
func (ErrorType) UserErrorf ¶
UserErrorf creates a new error with a user readable message.
func (ErrorType) UserWrapf ¶
UserWrapf adds a formatted user readable message to an error. If wrapped err already had a user message, combines them with a colon, you should not add a %s for it. Also sets error type (or preserves existing type if called on NoType). If wrapped err is nil, still returns a new error.