Documentation ¶
Overview ¶
Package ddderr -or DDD Error- is a generic domain-driven exception wrapper made for Go.
DDD Error aims to ease the lack of exception handling in The Go Programming Language by defining a wide selection of common exceptions which happen inside the domain and/or infrastructure layer(s).
DDD Error is dependency-free, it complies with Go's built-in error interface and avoids reflection to increase overall performance.
Index ¶
- func GetHttpStatusCode(err Error) int
- type Error
- func NewAlreadyExists(resource string) Error
- func NewDomain(title, description string) Error
- func NewInfrastructure(title, description string) Error
- func NewInvalidFormat(property string, formats ...string) Error
- func NewNotFound(resource string) Error
- func NewOutOfRange(property string, a, b int) Error
- func NewRemoteCall(externalResource string) Error
- func NewRequired(property string) Error
- func (e Error) Description() string
- func (e Error) Error() string
- func (e Error) IsAlreadyExists() bool
- func (e Error) IsDomain() bool
- func (e Error) IsInfrastructure() bool
- func (e Error) IsInvalidFormat() bool
- func (e Error) IsNotFound() bool
- func (e Error) IsOutOfRange() bool
- func (e Error) IsRemoteCall() bool
- func (e Error) IsRequired() bool
- func (e Error) Kind() string
- func (e Error) Parent() error
- func (e Error) Property() string
- func (e Error) SetDescription(description string) Error
- func (e Error) SetKind(kind string) Error
- func (e Error) SetParent(err error) Error
- func (e Error) SetProperty(property string) Error
- func (e Error) SetStatus(status string) Error
- func (e Error) SetTitle(title string) Error
- func (e Error) Status() string
- func (e Error) Title() string
- type HttpError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHttpStatusCode ¶
GetHttpStatusCode retrieves an HTTP status code from the given error
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error contains specific mechanisms useful for further error mapping and other specific use cases
func NewAlreadyExists ¶
NewAlreadyExists creates an Error for Already Exists use cases
(description e.g. The resource foo was already created)
func NewInfrastructure ¶
NewInfrastructure creates an Error for Infrastructure generic use cases
func NewInvalidFormat ¶
NewInvalidFormat creates an Error for Invalid Format use cases
(description e.g. The property foo has an invalid format, expected [x1, x2, xN])
func NewNotFound ¶
NewNotFound creates an Error for Not Found use cases
(description e.g. The resource foo was not found)
func NewOutOfRange ¶
NewOutOfRange creates an Error for Out of Range use cases
(description e.g. The property foo is out of range [A, B))
func NewRemoteCall ¶
NewRemoteCall creates an Error for network remote calls failing scenarios
(e.g. database connection failed, sync inter-service transaction failed over a networking problem)
func NewRequired ¶
NewRequired creates an Error for Required use cases
(description e.g. The property foo is required)
func (Error) Description ¶
Description retrieves a specific and detailed error message
func (Error) IsAlreadyExists ¶
IsAlreadyExists checks if the error belongs to Already Exists error types
func (Error) IsInfrastructure ¶
IsInfrastructure checks if the error belongs to Infrastructure error group
func (Error) IsInvalidFormat ¶
IsInvalidFormat checks if the error belongs to Invalid Format error types
func (Error) IsNotFound ¶
IsNotFound checks if the error belongs to Not Found error types
func (Error) IsOutOfRange ¶
IsOutOfRange checks if the error belongs to Out of Range error types
func (Error) IsRemoteCall ¶
IsRemoteCall checks if the error belongs to Failed Remote Call error types
func (Error) IsRequired ¶
IsRequired checks if the error belongs to Required error types
func (Error) Parent ¶
Parent returns the error parent
Note: Might return nil if parent was not specified
func (Error) SetDescription ¶
SetDescription sets a specific and detailed error message
func (Error) SetProperty ¶
SetProperty sets the field or resource for an error
type HttpError ¶
type HttpError struct { Type string `json:"type,omitempty"` Title string `json:"title,omitempty"` Status string `json:"status,omitempty"` StatusCode int `json:"status_code,omitempty"` Detail string `json:"detail,omitempty"` Instance string `json:"instance,omitempty"` }
HttpError is an RFC-compliant HTTP protocol problem object.
For more information about the fields, please go to: https://datatracker.ietf.org/doc/html/rfc7807
func NewHttpError ¶
NewHttpError builds an HttpError from the given DDD error