partyerrors

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnsupportedErrorCause = NewCause(InternalServerErrorCategory, "unsupported_error")
	UnknownCause          = NewCause(InternalServerErrorCategory, "unknown_cause")
	ProgrammerErrorCause  = NewCause(InternalServerErrorCategory, "programmer_error")
	InvalidArgumentCause  = NewCause(BadRequestCategory, "invalid_argument")
	InvalidStateCause     = NewCause(BadRequestCategory, "invalid_state")
	TimeoutCause          = NewCause(RequestTimeoutCategory, "timeout")
	NotImplementedCause   = NewCause(NotImplementedCategory, "not_implemented")
)

List of all possible causes

View Source
var (
	ErrNotImplemented = New(NotImplementedCause, "Not Implemented")
)

Functions

func CausedBy

func CausedBy(err error, c Cause) bool

CausedBy check if an error has a given cause

func ErrorFromBytes

func ErrorFromBytes(data []byte) error

func FromCause

func FromCause(e error, c Cause) bool

FromCause returns whether or not an error was caused by the provided cause

Types

type Category

type Category string

Category is a category of cause

var (
	BadRequestCategory          Category = "bad_request"
	UnauthorizedCategory        Category = "unauthorized"
	NotFoundCategory            Category = "not_found"
	InternalServerErrorCategory Category = "internal_error"
	NotImplementedCategory      Category = "not_implemented"
	MethodNotAllowedCategory    Category = "method_not_allowed"
	ConflictCategory            Category = "conflict"
	ForbiddenCategory           Category = "forbidden"
	RequestTimeoutCategory      Category = "request_timeout"
)

List of all error categories

func CategoryForStatusCode

func CategoryForStatusCode(code int) (Category, bool)

CategoryForStatusCode convert an http status code to a category

func (Category) String

func (t Category) String() string

String returns the stringified name of the category

type Cause

type Cause struct {
	Name     string
	Category Category
}

Cause is the cause of an error

func NewCause

func NewCause(c Category, name string) Cause

NewCause creates a new cause of an error

type Error

type Error struct {
	Cause    Cause    `json:"cause"`
	Messages []string `json:"messages"`
}

Error represents an Error returned by a middleware or route handler to a requestor.

Completes the HTTPError interface

The ID may or may not be a NullID depending on the source of the error - if its unmarshaled from the old error format then it will be a NullID. Error is an error

func New

func New(c Cause, msg string, args ...interface{}) *Error

New creates a new error

func NewMulti

func NewMulti(c Cause, msgs []string, args ...interface{}) *Error

NewMulti creates a new error containing multiple error messages

func ToError

func ToError(e error) *Error

ToError mutates a given error into an *Error, if the error is not a *Error then it mutates it into an InternalServerError with a corresponding message.

func Wrap

func Wrap(c Cause, err error) *Error

Wrap an error inside an error associated with a Cause

func WrapMulti

func WrapMulti(c Cause, errs []error) *Error

WrapMulti an multiple errors inside an error associated with a Cause

func (*Error) Code

func (e *Error) Code() int32

Code returns the HTTP Status Code associated with this Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode returns the HTTP Status Code associated with this Error

func (*Error) Validate

func (e *Error) Validate(_ interface{}) error

Validate returns an error if the error is an invalid error

type HTTPError

type HTTPError interface {
	error
	StatusCode() int
	Code() int32
}

HTTPError represents an error that is returned to a callee as an HTTP response

Jump to

Keyboard shortcuts

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