uerr

package
v0.0.0-...-ebe5785 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GenericError               = "Error"
	ResourceAlreadyExistsError = "ResourceAlreadyExistsError"
	ResourceNotFoundError      = "ResourceNotFoundError"
	WrongInputParameterError   = "WrongInputParameterError"
	UnauthorizedError          = "UnauthorizedError"
	ForbiddenError             = "ForbiddenError"
)

Variables

This section is empty.

Functions

func GetKey

func GetKey(err error) string

GetKey returns the key of the error if it is an UError or empty string if it is another error type.

func GetMessage

func GetMessage(err error) string

GetMessage returns the message of the error if it is an UError, err.Error() otherwise.

func HTTPCode

func HTTPCode(err error) int

HTTPCode maps the error keys to an HTTP status code.

func Is

func Is(err error, key string) bool

func IsForbidden

func IsForbidden(err error) bool

IsForbidden returns true if the error is a ForbiddenError.

func IsResourceAlreadyExists

func IsResourceAlreadyExists(err error) bool

IsResourceAlreadyExists returns true if the error is a IsResourceAlreadyExists.

func IsResourceNotFound

func IsResourceNotFound(err error) bool

IsResourceNotFound returns true if the error is a ResourceNotFoundError.

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized returns true if the error is a UnauthorizedError.

func IsWrongInputParameter

func IsWrongInputParameter(err error) bool

IsWrongInputParameter returns true if the error is a WrongInputParameterError.

Types

type UError

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

func FromBytes

func FromBytes(b []byte) (*UError, error)

FromBytes only builds Key and Message build from bytes, ignoring Cause.

func NewError

func NewError(key, message string) *UError

NewError creates a new UError with given key and message.

func (*UError) Error

func (c *UError) Error() string

Error returns the string representation of the error by calling String.

func (*UError) MarshalJSON

func (c *UError) MarshalJSON() ([]byte, error)

nolint:lll // long line needed MarshalJSON returns the json representation of the error, adding a parent key "error". Example 1: using a fmt.Errorf(...) as error cause. err := NewError("myKey", "myMessage").Cause(fmt.Errorf("myCause")) err.MarshalJSON() => {"error":{"key":"myKey","message":"myMessage","cause":"myCause"}}

Example 2: using another UError as error cause. err := NewError("myKey", "myMessage").Cause(NewError("myCauseKey", "myCauseMessage")) err.MarshalJSON() => {"error":{"key":"myKey","message":"myMessage","cause":{"error":{"key":"myKey","message":"myMessage"}}}}

func (*UError) String

func (c *UError) String() string

String returns the json representation of the error by calling MarshalJSON.

func (*UError) UnmarshalJSON

func (c *UError) UnmarshalJSON(b []byte) error

UnmarshalJSON builds a UError by calling FromBytes.

func (*UError) WithCause

func (c *UError) WithCause(err error) *UError

WithCause adds a cause to the error.

Jump to

Keyboard shortcuts

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