Documentation
¶
Index ¶
Constants ¶
const ( // EConflict Action cannot be performed EConflict = "conflict" // EInternal internal error EInternal = "internal" // EInvalid validation failed EInvalid = "invalid" // ENotFound entity not found/doesn't exist ENotFound = "not_found" // EAlreadyExists entity already exists EAlreadyExists = "already_exists" // EPermissionDenied Authenticated user does not have permission EPermissionDenied = "permission_denied" // EUnauthenticated Requestor does not have valid authentication to perform to operation EUnauthenticated = "unauthenticated" // ECannotDecode Data could not be decoded ECannotDecode = "cannot_decode" // ECannotEncode Data could not be encoded ECannotEncode = "cannot_encode" // ECannotParse Data could not be parsed ECannotParse = "cannot_parse" )
Variables ¶
This section is empty.
Functions ¶
func Code ¶
Code returns the error code of the uppermost error object if type is of era.Error; If the error is a regular error or no code is specified, Code returns era.EInternal; Providing the code of the highest error object encourages codes to be applied at each level of the stack.
func Hash ¶
Hash returns a five character hexadecimal hash of the error stack. This is useful for customer service and log analytics usecases as errors from the same cause can be quickly correlated. The hash function traverses down the error stack if the error is an era.Error, calculating the hash based on the Code, Message and Op. If the passed error is a regular error, Hash returns five zero characters.
func HighestCode ¶
HighestCode returns the highest defined error code of the error object if type is of era.Error; If the error is a regular error or no code is specified in the entire error stack, Code returns era.EInternal; Unlike Code(), HighestCode() will recurse down in order to find the first defined code.
func LowestCode ¶
LowestCode returns the lowest error code of the error, if available. Otherwise returns EInternal.
func Message ¶
Message returns the human-readable message of the error, if available. The message will be the lowest message in the stack. Otherwise returns a generic error message.
func Safe ¶
Safe should be used when errors leave the scope of the service, and enter into a consumers domain. Safe provides the consumer with the error code and message, neither of these components should expose sensitive information. Safe returns an error for compatability reasons, an http handler may expect an error to be returned in the case of failure.
Types ¶
type Error ¶
type Error struct {
// Machine-readable error code.
// Error codes can be custom, but a set of predefined codes are defined in codes.go.
Code string
// Human-readable message, potentially consumer facing error.
// This message can be delivered to a consumer as an indication of what happened and what they should do next.
Message string
// Logical operation
Op string
// Nested Error
Err error
}
Error defines a standard application error.
func WithCode ¶
WithCode adds an error code to the provided error. If the err is an era.Error && err.Code is undefined, the code is applied to the era.Error; If the err is an era.Error && err.Code is defined, the err is wrapped and the code is applied; If the err is a regular error, the error is wrapped and the code is applied.
func (*Error) Error ¶
Error returns the string representation of the error message. Error returns a string prefixed with the top