Documentation
¶
Index ¶
- Constants
- func ErrorCode(err error) string
- func ErrorData(err error) map[string]interface{}
- func ErrorMessage(err error) string
- func ErrorStacktrace(err error)
- func ErrorToGRPCCode(err error) codes.Code
- func ErrorToHTTPStatus(err error) int
- func GRPCCodeToError(c codes.Code) string
- func HTTPStatusToError(status int) string
- type Error
Constants ¶
const ( ECONFLICT = "conflict" // action cannot be performed EINTERNAL = "internal" // internal error EINVALID = "invalid" // validation failed ENOTFOUND = "not_found" // entity does not exist ENOTAUTHORIZED = "not_authorized" // requester does not have permissions to perform action ENOTAUTHENTICATED = "not_authenticated" // requester is not authenticated ERESOURCEEXHAUSTED = "resource_exhausted" // the resource has been exhausted ENOTIMPLEMENTED = "not_implemented" // the operation has not been implemented EUNAVAILABLE = "unavailable" // the system or operation is not available )
Application error codes
Variables ¶
This section is empty.
Functions ¶
func ErrorCode ¶
ErrorCode returns the code of the root error, if available. Otherwise returns EINTERNAL.
func ErrorMessage ¶
ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic error message.
func ErrorStacktrace ¶ added in v1.1.2
func ErrorStacktrace(err error)
ErrorStacktrace prints a human-redable stacktrace of all nested errors.
func ErrorToGRPCCode ¶ added in v1.0.1
ErrorToGRPCCode converts an standar application error code to a GRPC error code
func ErrorToHTTPStatus ¶ added in v1.1.0
ErrorToHTTPStatus converts an standar application error code to a HTTP status
func GRPCCodeToError ¶ added in v1.1.0
GRPCCodeToError converts a GRPC error code to a standar application error code
func HTTPStatusToError ¶ added in v1.1.0
HTTPStatusToError converts a HTTP error code to a standar application error code
Types ¶
type Error ¶
type Error struct {
// Machine readable code
Code string `json:"code"`
// Human readable message
Message string `json:"message"`
// Logical operation
Op string `json:"op"`
// Nested error
Err error `json:"err"`
// Data about the error
Data map[string]interface{} `json:"data,omitempty"`
}
Error defines a standar application error
func NewFromGRPC ¶ added in v1.0.1
NewFromGRPC wraps a GRPC Error into a standar application error
func Wrap ¶
Wrap returns a new error that contains the passed error but with a different operation, useful for creating stacktraces
func (*Error) AddDataMap ¶ added in v1.4.0
WithDataMap adds multiple key-value pairs to the error's data