Documentation
¶
Index ¶
- Constants
- func ErrorCode(err error) string
- func ErrorData(err error) map[string]interface{}
- func ErrorMessage(err error) string
- func ErrorStacktrace(err error) string
- 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" // request is valid but the current state of the data forbids it EINTERNAL = "internal" // unexpected internal failure where retry is not implied 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" // rate limit / quota exhausted ENOTIMPLEMENTED = "not_implemented" // the operation has not been implemented EUNAVAILABLE = "unavailable" // the operation is unavailable and retry may help ETIMEOUT = "timeout" // the operation ran out of time ECANCELED = "canceled" // the caller gave up before the operation finished )
Application error codes
const StatusClientClosedRequest = 499
StatusClientClosedRequest is nginx's non-standard status for requests canceled by the client. net/http has no constant for it.
Variables ¶
This section is empty.
Functions ¶
func ErrorCode ¶
ErrorCode returns the code from a direct ez error chain, if available. Timeouts and cancellations are detected through standard error wrappers so they don't get misreported as internal errors. Otherwise returns EINTERNAL.
func ErrorData ¶ added in v1.4.0
ErrorData returns the data from a direct ez error chain, if available.
func ErrorMessage ¶
ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic message: timeouts and cancellations get code-specific text, everything else the internal-error fallback.
func ErrorStacktrace ¶ added in v1.1.2
ErrorStacktrace returns a human-readable stacktrace of all nested errors, one per line: structured ez frames until the first foreign error, whose complete text is appended once. The trace is deliberately lossy past that point — ez frames below a foreign wrapper appear inside its flat text, not as structured lines.
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 status code to a standar application error code. Only statuses that indicate an unavailable service map to EUNAVAILABLE. Other 5xx statuses remain EINTERNAL because retryability is not implied.
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 New ¶
New creates and returns a new error. The operation is derived from the calling function: "pkg.Type.Method" or "pkg.Function".
func NewFromGRPC ¶ added in v1.0.1
NewFromGRPC wraps a GRPC Error into a standar application error. The operation is derived from the calling function. Status descriptions remain in Err and are never copied into the end-user-facing Message.
func Root ¶ added in v1.4.0
Root creates a new root error. The operation is derived from the calling function.
func Wrap ¶
Wrap returns a new error that contains the passed error, useful for creating stacktraces. The operation is derived from the calling function.
func (*Error) AddDataMap ¶ added in v1.4.0
WithDataMap adds multiple key-value pairs to the error's data