errors

package
v0.0.0-...-2c114f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrUnknown         = "unknown"
	ErrInternalService = "internal_service"
	ErrBadRequest      = "bad_request"
	ErrBadResponse     = "bad_response"
	ErrForbidden       = "forbidden"
	ErrUnauthorized    = "unauthorized"
	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

func Marshal

func Marshal(e *Error) *pe.Error

Marshal an error into a protobuf for transmission

func Wrap

func Wrap(err error, params map[string]string) error

Wrap takes any error interface and wraps it into an Error. This is useful because an Error contains lots of useful goodies, like the stacktrace of the error. NOTE: If `err` is already an `Error` the passed params will be ignored

func WrapWithCode

func WrapWithCode(err error, params map[string]string, code string) error

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

func BadRequest(code, message string, params map[string]string) *Error

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

func BadResponse(code, message string, params map[string]string) *Error

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

func Forbidden(code, message string, params map[string]string) *Error

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

func InternalService(code, message string, params map[string]string) *Error

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

func New(code string, message string, params map[string]string) *Error

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

func NotFound(code, message string, params map[string]string) *Error

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 Timeout

func Timeout(code, message string, params map[string]string) *Error

Timeout creates a new error representing a timeout from client to server

func Unauthorized

func Unauthorized(code, message string, params map[string]string) *Error

Unauthorized creates a new error indicating that authentication is required, but has either failed or not been provided.

func Unmarshal

func Unmarshal(p *pe.Error) *Error

Unmarshal a protobuf error into a local error

func (*Error) Error

func (p *Error) Error() string

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) Format

func (p *Error) Format(f fmt.State, c rune)

func (*Error) Matches

func (p *Error) Matches(match string) bool

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

func (p *Error) StackString() string

StackString formats the stack as a beautiful string with newlines

func (*Error) VerboseString

func (p *Error) VerboseString() string

VerboseString returns the error message, stack trace and params

Directories

Path Synopsis
totally stolen from https://github.com/stvp/rollbar/blob/master/stack.go
totally stolen from https://github.com/stvp/rollbar/blob/master/stack.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL