errors

package
v0.0.0-...-73b05ea Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause returns the underlying cause of the error, if possible. See https://godoc.org/github.com/pkg/errors#Cause for further details.

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf formats according to a format specifier and returns the string as a value that satisfies error. See https://godoc.org/github.com/pkg/errors#Errorf for further details

func LoadMessages

func LoadMessages(file string) error

LoadMessages reads a YAML file containing error templates.

func New

func New(message string) error

New returns an error with the supplied message. See https://godoc.org/github.com/pkg/errors#New for further details

func Wrap

func Wrap(err error, message string) error

Wrap returns an error annotating err with message. If err is nil, Wrap returns nil. See https://godoc.org/github.com/pkg/errors#Wrap for more details.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf returns an error annotating err with the format specifier. If err is nil, Wrapf returns nil. See https://godoc.org/github.com/pkg/errors#Wrapf for more details.

Types

type APIError

type APIError struct {
	// Status represents the HTTP status code
	Status int `json:"-"`
	// ErrorCode is the code uniquely identifying an error
	ErrorCode string `json:"error_code"`
	// Message is the error message that may be displayed to end users
	Message string `json:"message"`
	// DeveloperMessage is the error message that is mainly meant for developers
	DeveloperMessage string `json:"developer_message,omitempty"`
	// Details specifies the additional error information
	Details interface{} `json:"details,omitempty"`
}

APIError represents an error that can be sent in an error response.

func InternalServerError

func InternalServerError(err error) *APIError

InternalServerError creates a new API error representing an internal server error (HTTP 500)

func InvalidData

func InvalidData(errs validation.Errors) *APIError

InvalidData converts a data validation error into an API error (HTTP 400)

func NewHTTPError

func NewHTTPError(status int, code string, params Params) *APIError

NewHTTPError creates a new APIError with the given HTTP status code, error code, and parameters for replacing placeholders in the error template. The param can be nil, indicating there is no need for placeholder replacement.

func NotFound

func NotFound(resource string) *APIError

NotFound creates a new API error representing a resource-not-found error (HTTP 404)

func Unauthorized

func Unauthorized(err string) *APIError

Unauthorized creates a new API error representing an authentication failure (HTTP 401)

func (APIError) Error

func (e APIError) Error() string

Error returns the error message.

func (APIError) StatusCode

func (e APIError) StatusCode() int

StatusCode returns the HTTP status code.

type Params

type Params map[string]interface{}

Params is used to replace placeholders in an error template with the corresponding values.

type StackTracer

type StackTracer interface {
	StackTrace() errors.StackTrace
}

StackTracer represents a type (usually an error) that can provide a stack trace.

Jump to

Keyboard shortcuts

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