fail

package
v0.0.0-...-795d1f5 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2017 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxStackDepth = 50

MaxStackDepth is the maximum number of stack frames to report.

View Source
var ValidationErrorStatusCode = 422

ValidationErrorStatusCode represents the HTTP status code for ValidationError.

Functions

func NewPossibleRowNotFoundError

func NewPossibleRowNotFoundError(err error) error

NewPossibleRowNotFoundError determines if err matches sql.ErrNoRows and returns the err wrapped in a NotFoundError, otherwise the err returned as normal.

Types

type AuthenticationError

type AuthenticationError struct {
	Err
}

AuthenticationError represents a failure to authenticate.

func NewAuthError

func NewAuthError(code int, parts ...string) AuthenticationError

NewAuthError returns a new AuthenticationError to wrap the supplied error.

func (AuthenticationError) StatusCode

func (err AuthenticationError) StatusCode() int

StatusCode implements the `vc.StatusError` interface. Any AuthenticationError should return a 401 response.

type BadRequestError

type BadRequestError struct {
	Err
}

BadRequestError represents a bad request error.

func NewBadRequestError

func NewBadRequestError(err error) BadRequestError

NewBadRequestError returns a new BadRequestError to wrap the supplied error.

func (BadRequestError) StatusCode

func (err BadRequestError) StatusCode() int

StatusCode implements the `vc.StatusError` interface.

type Err

type Err struct {
	Code             int
	OriginalError    error
	Description      string
	AdditionalFields map[string]string
}

Err reprents a type that contains fields for additional error metadata. This type is generally extended with more domain specific context.

func (Err) Error

func (err Err) Error() string

Error implements the `error` interface.

func (Err) ErrorCode

func (err Err) ErrorCode() int

ErrorCode implements the `vc.ErrorCode` interface.

func (Err) ErrorDescription

func (err Err) ErrorDescription() string

ErrorDescription implements `vc.DescriptiveError` and should return a human readable description of the error.

func (Err) ErrorFields

func (err Err) ErrorFields() map[string]string

ErrorFields implements `vc.AnnotatedError` and should return a map of error details if appropriate.

func (*Err) WithField

func (err *Err) WithField(key, value string)

WithField is a chainable method that adds additional fields to the error.

func (*Err) WithFields

func (err *Err) WithFields(fields map[string]string)

WithFields is a chainable method that adds additional fields to the error.

type NotFoundError

type NotFoundError struct {
	Err
}

NotFoundError represents a resource not found.

func NewNotFoundError

func NewNotFoundError(err error) NotFoundError

NewNotFoundError returns a new NotFoundError to wrap the supplied error.

func (NotFoundError) StatusCode

func (err NotFoundError) StatusCode() int

StatusCode implements the `vc.StatusError` interface.

type PermissionsError

type PermissionsError struct {
	Err
}

PermissionsError represents a forbidden access request.

func NewPermissionsError

func NewPermissionsError(code int, parts ...string) PermissionsError

NewPermissionsError returns a new PermissionsError to wrap the supplied error. The parts slice elements refer to the original error and a more detailed description respectively.

func (PermissionsError) StatusCode

func (err PermissionsError) StatusCode() int

StatusCode implements the `vc.StatusError` interface.

type PossibleRowNotFoundError

type PossibleRowNotFoundError struct {
	Err
}

PossibleRowNotFoundError represents a resource not found.

func (PossibleRowNotFoundError) StatusCode

func (err PossibleRowNotFoundError) StatusCode() int

StatusCode implements the `vc.StatusError` interface.

type Private

type Private struct {
	ID            string
	PublicMessage string
	OriginalErr   error
	Code          int
}

Private masks an error with a public display message and tracking id to hide any sensitive system errors, and allow tracking of errors. Consumers should use the tracking id to link the public error to the private error message which should be logged into internal systems only.

func NewPrivate

func NewPrivate(err error) *Private

NewPrivate returns a private error wrapping the supplied error.

func (Private) Error

func (private Private) Error() string

Error implements the error interface.

func (Private) LogFields

func (private Private) LogFields() map[string]string

LogFields implements vc.StructuredLogsError and allows for the structured logging of the tracking id, and original private errors.

func (Private) StatusCode

func (private Private) StatusCode() int

StatusCode implements the StatusError interface.

func (*Private) WithMessage

func (private *Private) WithMessage(message string) *Private

WithMessage is a chainable method to set the public message.

func (*Private) WithStatusCode

func (private *Private) WithStatusCode(code int) *Private

WithStatusCode is a chainable method to set the status code.

type ServiceUnavailable

type ServiceUnavailable struct {
	Err
}

ServiceUnavailable represents a service unavailable error.

func NewServiceUnavailableError

func NewServiceUnavailableError(err error) ServiceUnavailable

NewServiceUnavailableError returns a new ServiceUnavailable to wrap the supplied error.

func (ServiceUnavailable) StatusCode

func (err ServiceUnavailable) StatusCode() int

StatusCode implements the `vc.StatusError` interface.

type StackTraceError

type StackTraceError struct {
	// contains filtered or unexported fields
}

StackTraceError wraps an error with the caller stack trace. Wrapping an error with a stack trace should occur at the boundary of your application code and external code. If an error comes from your own code, don't trace it, but if an error comes from third party code, such as opening a file, or running a db query, you should trace it so you know exactly where in your system the error occurred, and what path was taken to get there.

func (*StackTraceError) Error

func (err *StackTraceError) Error() string

Error implements the error interface, with the error, type and stack trace.

func (*StackTraceError) ErrorContext

func (err *StackTraceError) ErrorContext() map[string]interface{}

ErrorContext implements the api.ErrorContext interface.

func (StackTraceError) Stack

func (err StackTraceError) Stack() []byte

Stack returns the callstack formatted the same way that go does in runtime/debug.Stack()

func (*StackTraceError) StackFrames

func (err *StackTraceError) StackFrames() []errors.StackFrame

StackFrames returns an array of errors.StackFrames containing information about the stack.

func (*StackTraceError) WithContext

func (err *StackTraceError) WithContext(ctx map[string]interface{}) TraceFace

WithContext adds metadata to a stack trace error for context.

func (*StackTraceError) WithContextField

func (err *StackTraceError) WithContextField(key string, value interface{}) TraceFace

WithContextField adds a metadatum to a stack trace error for context.

type TraceFace

type TraceFace interface {
	Error() string
	WithContext(map[string]interface{}) TraceFace
	WithContextField(string, interface{}) TraceFace
	ErrorContext() map[string]interface{}
}

TraceFace is an interface that represents StackTraceError. By defining an interface, we're able to return a nil interface rather than a nil pointer. This allows comparison with nil, and therefore doesn't break error checking.

func Trace

func Trace(err error) TraceFace

Trace is a convenience wrapper for creating a StackTraceError around an error. Note this can be called with nil errors, for convenience.

type ValidationError

type ValidationError struct {
	Err
}

ValidationError represents a validation error.

func NewSchemaValidationError

func NewSchemaValidationError(schemaErrors []schema.ResultError) ValidationError

NewSchemaValidationError returns a ValidationError that contains information about every field that was invalid.

func NewValidationError

func NewValidationError(err error) ValidationError

NewValidationError returns a new ValidationError to wrap the supplied error.

func (ValidationError) StatusCode

func (err ValidationError) StatusCode() int

StatusCode implements the `vc.StatusError` interface. Any AuthenticationError should return a 401 response.

Jump to

Keyboard shortcuts

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