errors

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 2 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// CodeUnknown is the default code returned when the application doesn't attach any code into the error
	CodeUnknown CodeType = "UNKNOWN"
	// KindUnexpected is the default kind returned  when the application doesn't attach any kind into the error
	KindUnexpected KindType = "UNEXPECTED"
	// KindConflict are errors caused by requests with data that conflicts with the current state of the system
	KindConflict KindType = "CONFLICT"
	// KindInternal are errors caused by some internal fail like failed IO calls or invalid memory states
	KindInternal KindType = "INTERNAL"
	// KindInvalidInput are errors caused by some invalid values on the input
	KindInvalidInput KindType = "INVALID_INPUT"
	// KindNotFound are errors caused by any required resources that not exists on the data repository
	KindNotFound KindType = "NOT_FOUND"
	// KindUnauthentication are errors caused by an unauthenticated call
	KindUnauthenticated KindType = "UNAUTHENTICATED"
	// KindUnauthorized are errors caused by an unauthorized call
	KindUnauthorized KindType = "UNAUTHORIZED"
)

Variables

This section is empty.

Functions

func NewMissingRequiredDependency

func NewMissingRequiredDependency(name string) error

NewMissingRequiredDependency creates a new error that indicates a missing required dependency. It should be producing at struct constructors.

Types

type CodeType

type CodeType string

CodeType is a string that contains error's code description

func Code

func Code(err error) CodeType

Kind this method receives an error, then compares its interface type with the CustomError interface if the interfaces types matches, returns its Code

type CustomError

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

CustomError is a structure that encodes useful information about a given error. It's supposed to flow within the application in detriment of the the default golang error, since its Kind and Code attributes are the keys to express its semantic and uniqueness, respectively. It should be generated once by the peace of code that found the error (because it's where we have more context about the error), and be by passed to the upper layers of the application.

func New

func New(message string, args ...interface{}) CustomError

New returns a new instance of CustomError with the given message

func (CustomError) Error

func (ce CustomError) Error() string

Error returns CustomError message

func (CustomError) WithCode

func (ce CustomError) WithCode(code CodeType) CustomError

WithCode return a copy of the CustomError with the given CodeType filled

func (CustomError) WithKind

func (ce CustomError) WithKind(kind KindType) CustomError

WithKind return a copy of the CustomError with the given KindType filled

type KindType

type KindType string

KindType is a string that contains error's kind description

func Kind

func Kind(err error) KindType

Kind this method receives an error, then compares its interface type with the CustomError interface if the interfaces types matches, returns its kind

Jump to

Keyboard shortcuts

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