Documentation ¶
Index ¶
- func Is(err error, code Code) bool
- type Code
- type Error
- func BadRequest(format string, a ...interface{}) *Error
- func Forbidden(format string, a ...interface{}) *Error
- func FromHTTPStatus(status int, format string, a ...interface{}) *Error
- func InternalService(format string, a ...interface{}) *Error
- func NotFound(format string, a ...interface{}) *Error
- func PreconditionFailed(format string, a ...interface{}) *Error
- func Timeout(format string, a ...interface{}) *Error
- func Unauthorized(format string, a ...interface{}) *Error
- func WithCode(err interface{}, code Code) *Error
- func WithMessage(err interface{}, format string, a ...interface{}) *Error
- func WithMetadata(err interface{}, metadata map[string]string) *Error
- func Wrap(err interface{}, code Code, format string, a ...interface{}) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Code ¶
type Code string
Code is an identifier of a particular class of error
const ( ErrBadRequest Code = "bad_request" ErrForbidden Code = "forbidden" ErrInternalService Code = "internal_service" ErrNotFound Code = "not_found" ErrPreconditionFailed Code = "precondition_failed" ErrTimeout Code = "timeout" )
Generic error codes. Each of these has their own constructor for convenience.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a custom error type that implements Go's error interface
func BadRequest ¶
BadRequest creates a new error to represent an error caused by the client sending an invalid request. This is non-retryable unless the request is modified.
func Forbidden ¶
Forbidden creates a new error representing a resource that cannot be accessed with the current authorisation credentials. The user may need authorising, or if authorised, may not be permitted to perform this action.
func FromHTTPStatus ¶
FromHTTPStatus returns an error where the code is derived from the HTTP status code
func InternalService ¶
InternalService creates a new error to represent an internal service error
func PreconditionFailed ¶
PreconditionFailed creates a new error indicating that one or more conditions given in the request evaluated to false when tested on the server
func Unauthorized ¶
Unauthorized creates a new error indicating that authentication is required, but has either failed or not been provided.
func WithMessage ¶
WithMessage wraps the error with an extra message
func WithMetadata ¶
WithMetadata will wrap the error with extra metadata
func Wrap ¶
Wrap wraps the given error. Optionally, the last parameter can be a map[string]string containing metadata. If the error-to-wrap is already an *Error, the metadata will me merged and the existing code will remain the same. If the error is not an *Error, the code will default to ErrInternalService.
func (*Error) GetCode ¶
GetCode unwinds the error stack and returns the first code encountered. If no codes exist, then ErrInternalService is returned.
func (*Error) GetMessage ¶
GetMessage returns the error's message. If there is a cause, its error message is appended after a colon, and so on.
func (*Error) GetMetadata ¶
GetMetadata returns the metadata map of the error
func (*Error) HTTPStatus ¶
HTTPStatus returns an appropriate HTTP status code to use when returning the error in a response
func (*Error) Matches ¶
Matches returns whether the string returned from error.Error() contains the given param string
func (*Error) StackTrace ¶
func (e *Error) StackTrace() pkgerrors.StackTrace
StackTrace returns the stack of Frames from innermost (newest) to outermost (oldest)