Documentation
¶
Index ¶
- Constants
- func CallerFunctionName() string
- func CurrentFunctionName() string
- func ErrorCode(err error) errorCode
- func ErrorFields(err error) map[string]interface{}
- func ErrorMessage(err error) string
- func ErrorMessageDefault(err error, def string) string
- func ErrorTrace(err error) []string
- func ErrorWithCode(err error, code errorCode) error
- func OpError(op string, err error) error
- func OpErrorOrNil(op string, err error) error
- type Error
Constants ¶
const ( // ECONFLICT Action cannot be performed. ECONFLICT errorCode = "conflict" // EINTERNAL internal error. EINTERNAL errorCode = "internal" // EINVALID validation failed. EINVALID errorCode = "invalid" // ENOTFOUND entity not found/doesn't exist. ENOTFOUND errorCode = "not_found" // ENOTMODIFIED entity not modified. ENOTMODIFIED errorCode = "not_modified" // EALREADYEXISTS entity already exists. EALREADYEXISTS errorCode = "already_exists" // EPermissionDenied user does not have permission. EPERMISSIONDENIED errorCode = "permission_denied" // EUNAUTHENTICATED Requestor does not have valid authentication to perform to operation. EUNAUTHENTICATED errorCode = "unauthenticated" // ECANNOTDECODE Data could not be decoded. ECANNOTDECODE errorCode = "cannot_decode" // ECANNOTENCODE Data could not be encoded. ECANNOTENCODE errorCode = "cannot_encode" // ECANNOTPARSE Data could not be parsed. ECANNOTPARSE errorCode = "cannot_parse" // EBEHAVIOUR something that must not be. EBEHAVIOUR errorCode = "undefined_behavior" // EUNSUPPORTED means that we dont support some actions // and this actions should be handled by others. EUNSUPPORTED errorCode = "unsupported" // ETEST test error code, useful for testing. ETEST errorCode = "test_error_code" DefaultErrorMessage = "An internal error has occurred" )
Application error codes.
Variables ¶
This section is empty.
Functions ¶
func CallerFunctionName ¶
func CallerFunctionName() string
func CurrentFunctionName ¶
func CurrentFunctionName() string
func ErrorCode ¶
func ErrorCode(err error) errorCode
ErrorCode returns the code of the error, if available. Otherwise returns EINTERNAL.
func ErrorFields ¶
func ErrorMessage ¶
ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic error message.
func ErrorMessageDefault ¶
ErrorMessage returns the human-readable message of the error, if available. Otherwise returns default message if default is not empty, otherwise return err.Error().
func ErrorTrace ¶
func ErrorWithCode ¶
ErrorWithCode adds an error code to the provided error. If Error.Op is undefined, caller function name will be used as Op If the err is an Error && err.Code is undefined, the code is applied to the Error; If the err is an 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 OpErrorOrNil ¶
Types ¶
type Error ¶
type Error struct {
// Wrapped error
Err error `json:"err"`
// Some context of error
Fields map[string]interface{}
// Machine-readable error code.
Code errorCode `json:"code"`
// Human-readable message.
Message string `json:"message"`
// Logical operation.
Op string `json:"op"`
}
Error defines a standard application error.