Documentation
¶
Overview ¶
Package apperr defines framework-free application errors.
Index ¶
- Constants
- func HTTPStatus(code int) int
- func IsClientError(code int) bool
- func IsInternalError(code int) bool
- func IsServerError(code int) bool
- func New(code int, message string) error
- func NewBadRequest(message string) error
- func NewConflict(message string) error
- func NewForbidden() error
- func NewMethodNotAllowed(message string) error
- func NewNotFound(resource string) error
- func NewPermissionDenied(resource, action string) error
- func NewTokenExpired() error
- func NewTokenInvalid() error
- func NewUnauthorized() error
- func NewValidation(field, message string) error
- func Newf(code int, format string, args ...interface{}) error
- func Wrap(err error, code int, message string) error
- func WrapBadRequest(err error, message string) error
- func WrapConflict(err error, message string) error
- func WrapDatabase(err error, operation string) error
- func WrapExternal(err error, service, operation string) error
- func WrapForbidden(err error, message string) error
- func WrapInternal(err error, message string) error
- func WrapKafka(err error, operation string) error
- func WrapMethodNotAllowed(err error, message string) error
- func WrapNotFound(err error, message string) error
- func WrapRedis(err error, operation string) error
- func WrapUnauthorized(err error, message string) error
- func Wrapf(err error, code int, format string, args ...interface{}) error
- type Category
- type Definition
- type Error
- type Info
- type Kind
Constants ¶
const ( ErrSuccess int = iota + 100001 ErrUnknown ErrBind ErrValidation ErrTokenInvalid )
Common application error codes.
const ( ErrDatabase int = iota + 100101 ErrRedis ErrKafka ErrExternalService )
Data source and external system error codes.
const ( ErrBadRequest = 100400 ErrForbidden = 100403 ErrNotFound = 100404 ErrMethodNotAllowed = 100405 ErrConflict = 100409 ErrSystemUninitialized = 100410 ErrInternalServer = 100500 )
Common request error codes.
const ( ErrEncrypt int = iota + 100201 ErrSignatureInvalid ErrExpired ErrInvalidAuthHeader ErrMissingHeader ErrPasswordIncorrect ErrPermissionDenied ErrAccountLocked ErrAccountDisabled ErrTooManyAttempts )
Authentication and authorization error codes.
const ( ErrEncodingFailed int = iota + 100301 ErrDecodingFailed ErrInvalidJSON ErrEncodingJSON ErrDecodingJSON ErrInvalidYaml ErrEncodingYaml ErrDecodingYaml )
Encoding and decoding error codes.
Variables ¶
This section is empty.
Functions ¶
func HTTPStatus ¶
HTTPStatus returns the HTTP status associated with a registered application error code. Unknown codes are treated as internal server errors.
func IsClientError ¶
IsClientError reports whether code maps to a 4xx HTTP status.
func IsInternalError ¶
IsInternalError reports whether code should be handled as an internal error.
func IsServerError ¶
IsServerError reports whether code maps to a 5xx HTTP status.
func NewBadRequest ¶
NewBadRequest creates a bad request error.
func NewMethodNotAllowed ¶
NewMethodNotAllowed creates a method-not-allowed error.
func NewNotFound ¶
NewNotFound creates a not found error for resource.
func NewPermissionDenied ¶
NewPermissionDenied creates a permission-denied error.
func NewValidation ¶
NewValidation creates a validation error.
func WrapBadRequest ¶
WrapBadRequest wraps a bad request error.
func WrapConflict ¶
WrapConflict wraps a conflict error.
func WrapDatabase ¶
WrapDatabase wraps database errors.
func WrapExternal ¶
WrapExternal wraps external service errors.
func WrapForbidden ¶
WrapForbidden wraps a forbidden error.
func WrapInternal ¶
WrapInternal wraps an internal server error.
func WrapMethodNotAllowed ¶
WrapMethodNotAllowed wraps a method-not-allowed error.
func WrapNotFound ¶
WrapNotFound wraps a not found error.
func WrapUnauthorized ¶
WrapUnauthorized wraps an unauthorized error.
Types ¶
type Category ¶
type Category string
Category identifies the operational area associated with an error.
const ( CategorySystem Category = "system" CategoryDatabase Category = "database" CategoryRedis Category = "redis" CategoryKafka Category = "kafka" CategoryExternal Category = "external" CategoryAuth Category = "auth" CategoryPermission Category = "permission" CategoryValidation Category = "validation" CategoryBusiness Category = "business" )
Application error categories.
type Definition ¶
Definition is the registered meaning of an application error code.
func Lookup ¶
func Lookup(code int) (Definition, bool)
Lookup returns the registered definition for code.
func ParseRegistered ¶
func ParseRegistered(err error) (Definition, bool)
ParseRegistered returns the first registered application error definition in err's unwrap chain.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error carries a code, safe message, diagnostic detail, and wrapped cause.
type Info ¶
Info is the normalized application error information used by logs and delivery adapters.
func (Info) IsBusiness ¶
IsBusiness reports whether info represents a non-internal error.
func (Info) IsInternal ¶
IsInternal reports whether info represents an internal error.
type Kind ¶
type Kind string
Kind describes the caller-visible class of an application error without depending on HTTP.
const ( KindOK Kind = "ok" KindBadRequest Kind = "bad_request" KindValidation Kind = "validation" KindForbidden Kind = "forbidden" KindNotFound Kind = "not_found" KindMethodNotAllowed Kind = "method_not_allowed" KindConflict Kind = "conflict" KindInternal Kind = "internal" )
Application error kinds.