errors

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseError

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

BaseError generalizes an error structure which can be used for any type of error

func BaseErrorWrapper added in v1.0.14

func BaseErrorWrapper(err Error) BaseError

BaseErrorWrapper creates a new BaseError by wrapping an existing Error

func NewBaseError

func NewBaseError(kind ErrKind, errMsg string, err error, detail ErrDetails) BaseError

NewBaseError creates a new BaseError with the information provided

func ToBaseError

func ToBaseError(err error) BaseError

ToBaseError creates a new BaseError with Kind found from err

func (BaseError) AddDetail

func (be BaseError) AddDetail(key string, detail any)

AddDetail adds a detail associated with key for this BaseError.

func (BaseError) DebugMessages

func (be BaseError) DebugMessages() string

DebugMessages returns a string taking all nested and wrapped operations and errors into account.

func (BaseError) Details

func (be BaseError) Details() ErrDetails

Details returns the detail maps of this BaseError.

func (BaseError) Error

func (be BaseError) Error() string

Error implements the Error interface for the BaseError struct

func (BaseError) Is

func (be BaseError) Is(err error) bool

Is determines if an error is of type BaseError. This is used by the new wrapping and unwrapping features available in Go 1.13 and aids the errors.Is function when determining is an error or any error in the wrapped chain contains an error of a particular type.

func (BaseError) Kind

func (be BaseError) Kind() ErrKind

Kind returns the error kind of this BaseError.

func (BaseError) Message

func (be BaseError) Message() string

Message returns the first level error message without further details.

func (BaseError) Unwrap

func (be BaseError) Unwrap() error

Unwrap retrieves the next nested error in the wrapped error chain. This is used by the new wrapping and unwrapping features available in Go 1.13 and aids in traversing the error chain of wrapped errors.

type ErrDetails

type ErrDetails map[string]any

ErrDetails is a detailed mapping to set extra information with the error

type ErrKind

type ErrKind string

ErrKind a categorical identifier used to give high-level insight as to the error type.

const (
	// Constant Kind identifiers which can be used to label and group errors.
	KindUnknown               ErrKind = "Unknown"
	KindDatabaseError         ErrKind = "Database"
	KindCommunicationError    ErrKind = "Communication"
	KindEntityDoesNotExist    ErrKind = "NotFound"
	KindContractInvalid       ErrKind = "ContractInvalid"
	KindServerError           ErrKind = "UnexpectedServerError"
	KindLimitExceeded         ErrKind = "LimitExceeded"
	KindStatusConflict        ErrKind = "StatusConflict"
	KindDuplicateName         ErrKind = "DuplicateName"
	KindInvalidId             ErrKind = "InvalidId"
	KindServiceUnavailable    ErrKind = "ServiceUnavailable"
	KindNotAllowed            ErrKind = "NotAllowed"
	KindServiceLocked         ErrKind = "ServiceLocked"
	KindNotImplemented        ErrKind = "NotImplemented"
	KindRangeNotSatisfiable   ErrKind = "RangeNotSatisfiable"
	KindIOError               ErrKind = "IOError"
	KindOverflowError         ErrKind = "OverflowError"
	KindNaNError              ErrKind = "NaNError"
	KindUnauthorized          ErrKind = "Unauthorized"
	KindAuthenticationFailure ErrKind = "AuthenticationFailure"
	KindPayloadDecodeFailure  ErrKind = "PayloadDecodeFailure"
	KindTimeout               ErrKind = "Timeout"
)

func Kind

func Kind(err error) ErrKind

Kind determines the Kind associated with an error by inspecting the chain of errors. The first non-KindUnknown Kind found from the chain of wrappedErr is returned. If Kind cannot be determined from wrappedErr, KindUnknown is returned

func KindMapping

func KindMapping(code int) ErrKind

KindMapping determines the correct error kind for the given HTTP response code.

type Error

type Error interface {
	// Error obtains the error message associated with the error.
	Error() string
	// Message returns the first level error message without further details.
	Message() string
	// DebugMessages returns a detailed string for debug purpose.
	DebugMessages() string
	// Kind returns the error kind of this edge error.
	Kind() ErrKind
	// Details returns the detailed mapping associated with this edge error.
	Details() ErrDetails
}

Error provides an abstraction for all internal errors. This exists so that we can use this type in our method signatures and return nil which will fit better with the way the Go builtin errors are normally handled.

type HTTPError

type HTTPError struct {
	BaseError
	// contains filtered or unexported fields
}

func NewHTTPError

func NewHTTPError(wrappedError error) HTTPError

func (HTTPError) Code added in v1.0.8

func (he HTTPError) Code() int

Code returns the status code of this error.

func (HTTPError) Message

func (he HTTPError) Message() string

Jump to

Keyboard shortcuts

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