Documentation ¶
Overview ¶
Package errors defines structured errors which can be used for nesting errors with propagation of error identifiers and their messages. It also supports JSON serialization, so service to service communication can preserve error Kind.
Index ¶
Constants ¶
const Alphabet string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(args ...interface{}) error
New builds an error value from its arguments. There must be at least one argument or New panics. The type of each argument determines its meaning. If more than one argument of a given type is presented, only the last one is recorded.
The supported types are:
errors.Kind: The kind of the error. *errors.Error The underlying error that triggered this one. If the error has non-empty ID and Kind fields, they are promoted as values of the returned one. error: The underlying error that triggered this one. string: Treated as an error message and assigned to the Message field.
Types ¶
type Error ¶
type Error struct { // ID is a unique error identifier. ID string // Kind of error returned to the caller. Kind Kind // Message is a description of the error. Message string // The underlying error that triggered this one, if any. Err error }
func (*Error) MarshalJSON ¶
MarshalJSON returns the JSON representation of an Error.
func (*Error) StatusCode ¶
StatusCode returns the HTTP status code corresponding to the error.
func (*Error) Temporary ¶
Temporary reports if an Error is temporary and whether the request can be retried.
func (*Error) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON encoded Error.
type Kind ¶
type Kind int
const ( Unknown Kind = iota // Unknown error. BadRequest // BadRequest specifies invalid arguments or operation. Forbidden // Forbidden operation. Exist // Exist already. NotFound // NotFound specifies that a resource does not exist. Timeout // Timeout of request. Internal // Internal error or inconsistency. )