errors

package
v0.0.0-...-882f8d2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//SeverityUnset indicates the severity was not set
	SeverityUnset = Severity("")
	// SeverityRuntime indicates the error is returned for an operation that should/could be executed again. For example, timeouts.
	SeverityRuntime = Severity("runtime")
	// SeverityFatal indicates the error is unrecoverable and the execution should stop, or not being retried.
	SeverityFatal = Severity("fatal")
	// SeverityInput indicates  an expected, like a bad user input/request. For example, an invalid email.
	SeverityInput = Severity("input")
)
View Source
const (
	// ErrorCodeEmpty is an empty error code
	ErrorCodeEmpty = Code("")
)

Variables

This section is empty.

Functions

func ConcatErrors

func ConcatErrors(errs ...error) error

ConcatErrors concatenates all errors

func ConcatErrorsMessage

func ConcatErrorsMessage(errs ...error) string

ConcatErrorsMessage concatenates all the error messages from the given errors

func E

func E(args ...interface{}) error

E is a helper hunction for builder errors

func Errorf

func Errorf(s string, params ...interface{}) error

Errorf returns a error based on given params

func GetRootError

func GetRootError(err error) error

GetRootError returns the Err field of Error struct or the error itself if it is of another type

func GetRootErrorWithKV

func GetRootErrorWithKV(err error) error

GetRootErrorWithKV returns the Err field of Error struct or the error itself if it is of another type

func New

func New(s string) error

New returns a new error

Types

type Code

type Code string

Code is the error code

func GetErrorCode

func GetErrorCode(err error) Code

GetErrorCode returns the error code. If the error doen't contains an error code, returns ErrorCodeEmpty.

func (Code) String

func (c Code) String() string

String returns the code as a string

type Error

type Error struct {
	Severity   Severity
	Err        error
	Code       Code
	Op         Op
	HTTPStatus HTTPStatus
	KVs        []KeyValue
}

Error represents the error struct that should be returned in all functions Error implements the Go's error interface

func (Error) Error

func (e Error) Error() string

func (Error) String

func (e Error) String() string

type HTTPStatus

type HTTPStatus int

HTTPStatus sets an http status for the error

func GetHTTPStatus

func GetHTTPStatus(err error) HTTPStatus

GetHTTPStatus returns the HTTPStatus of an error.

func (HTTPStatus) Int

func (s HTTPStatus) Int() int

Int returns the HTTP status

func (HTTPStatus) String

func (s HTTPStatus) String() string

type KeyValue

type KeyValue struct {
	Key   interface{}
	Value interface{}
}

KeyValue is used to store a key-value pair within the error

func KV

func KV(k, v interface{}) KeyValue

KV is a constructor for KeyValue types

func (KeyValue) String

func (kv KeyValue) String() string

type Op

type Op string

Op is the operation that encapsulated the error

func (Op) String

func (o Op) String() string

type Severity

type Severity string

Severity is the error severity. It's used to classify errors in groups to be easily handled by the code. For examle, a retry layer should be only checking for Runtime erros to retry. Or in an HTTP layer, erros of input type are always returned a 400 status.

func GetSeverity

func GetSeverity(err error) Severity

GetSeverity returns the error severity. If there is not severity, SeverityUnset is returned.

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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