Documentation ¶
Index ¶
- Constants
- func Marshal(e *Error) *pe.Error
- func Wrap(err error, params map[string]string) error
- func WrapWithCode(err error, params map[string]string, code string) error
- type Error
- func BadRequest(code, message string, params map[string]string) *Error
- func BadResponse(code, message string, params map[string]string) *Error
- func Forbidden(code, message string, params map[string]string) *Error
- func InternalService(code, message string, params map[string]string) *Error
- func New(code string, message string, params map[string]string) *Error
- func NotFound(code, message string, params map[string]string) *Error
- func Timeout(code, message string, params map[string]string) *Error
- func Unauthorized(code, message string, params map[string]string) *Error
- func Unmarshal(p *pe.Error) *Error
Constants ¶
const ( ErrUnknown = "unknown" ErrInternalService = "internal_service" ErrBadRequest = "bad_request" ErrBadResponse = "bad_response" ErrForbidden = "forbidden" ErrNotFound = "not_found" ErrTimeout = "timeout" )
Generic error codes. Each of these has their own constructor for convenience. You can use any string as a code, just use the `New` method.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct { Code string `json:"code"` Message string `json:"message"` Params map[string]string `json:"params"` StackFrames stack.Stack `json:"stack"` }
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 BadResponse ¶
BadResponse creates a new error representing a failure to response with a valid response Examples of this would be a handler returning an invalid message format
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 InternalService ¶
InternalService creates a new error to represent an internal service error. Only use internal service error if we know very little about the error. Most internal service errors will come from `Wrap`ing a vanilla `error` interface
func New ¶
New creates a new error for you. Use this if you want to pass along a custom error code. Otherwise use the handy shorthand factories below
func NotFound ¶
NotFound creates a new error representing a resource that cannot be found. In some cases this is not an error, and would be better represented by a zero length slice of elements
func Unauthorized ¶
Unauthorized creates a new error indicating that authentication is required, but has either failed or not been provided.
func (*Error) Error ¶
Error returns a string message of the error. It is a concatenation of Code and Message params This means the Error implements the error interface
func (*Error) Matches ¶
Matches returns whether the string returned from error.Error() contains the given param string. This means you can match the error on different levels e.g. dotted codes `bad_request` or `bad_request.missing_param` or even on the more descriptive message
func (*Error) StackString ¶
StackString formats the stack as a beautiful string with newlines
func (*Error) VerboseString ¶
VerboseString returns the error message, stack trace and params