cher

package
v0.0.0-...-4eb781d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

View Source
const (
	BadRequest        = "bad_request"
	Unauthorized      = "unauthorized"
	AccessDenied      = "access_denied"
	NotFound          = "not_found"
	RouteNotFound     = "route_not_found"
	MethodNotAllowed  = "method_not_allowed"
	Unknown           = "unknown"
	NoLongerSupported = "no_longer_supported"
	TooManyRequests   = "too_many_requests"
	ContextCanceled   = "context_canceled"
	EOF               = "eof"
	UnexpectedEOF     = "unexpected_eof"
	RequestTimeout    = "request_timeout"
	ThirdPartyTimeout = "third_party_timeout"

	CoercionError = "unable_to_coerce_error"
)

errors that are expected to be common across services

Variables

This section is empty.

Functions

func CoerceThirdPartyTimeout

func CoerceThirdPartyTimeout(err error) error

func WrapIfNotCher

func WrapIfNotCher(err error, msg string) error

WrapIfNotCher will not wrap the error if it is any cher except unknown.

Unless you don't know the codes you could get back, you should use WrapIfNotCherCodes.

func WrapIfNotCherCodes

func WrapIfNotCherCodes(err error, msg string, codes []string) error

WrapIfNotCherCodes will wrap an error unless it is a cher with specific codes.

Types

type E

type E struct {
	Code    string `json:"code"`
	Meta    M      `json:"meta,omitempty"`
	Reasons []E    `json:"reasons,omitempty"`
}

E implements the official Cuvva Error structure

func Coerce

func Coerce(v interface{}) E

Coerce attempts to coerce a Cuvva Error out of any object. - `E` types are just returned as-is - strings are taken as the Code for an E object - bytes are unmarshaled from JSON to an E object - types implementing the `error` interface to an E object with the error as a reason

func Errorf

func Errorf(code string, meta M, format string, args ...interface{}) E

Errorf returns a new E structure, with a message formatted by fmt.

func New

func New(code string, meta M, reasons ...E) E

New returns a new E structure with code, meta, and optional reasons.

func (E) Error

func (e E) Error() string

Error implements the error interface.

func (E) Serialize

func (e E) Serialize() string

Serialize returns a json representation of the Cuvva Error structure

func (E) StatusCode

func (e E) StatusCode() int

StatusCode returns the HTTP Status Code associated with the current error code. Defaults to 400 Bad Request because if something's explicitly handled with Cher, it is considered "by design" and not worthy of a 500, which will alert.

func (E) Value

func (e E) Value() (driver.Value, error)

type M

type M map[string]interface{}

M it an alias type for map[string]interface{}

Jump to

Keyboard shortcuts

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