Documentation ¶
Index ¶
- Variables
- func GetGroupNames() []string
- func ServeJSON(w http.ResponseWriter, err error) error
- type Error
- type ErrorCode
- func (ec ErrorCode) Descriptor() ErrorDescriptor
- func (ec ErrorCode) Error() string
- func (ec ErrorCode) ErrorCode() ErrorCode
- func (ec ErrorCode) MarshalText() (text []byte, err error)
- func (ec ErrorCode) Message() string
- func (ec ErrorCode) String() string
- func (ec *ErrorCode) UnmarshalText(text []byte) error
- func (ec ErrorCode) WithArgs(args ...interface{}) Error
- func (ec ErrorCode) WithDetail(detail interface{}) Error
- type ErrorCoder
- type ErrorDescriptor
- type Errors
Constants ¶
This section is empty.
Variables ¶
var ErrorCodeUnknown = Register("errcode", ErrorDescriptor{ Value: "UNKNOWN", Message: "unknown error", Description: `Generic error returned when the error does not have an API classification.`, HTTPStatusCode: http.StatusInternalServerError, })
ErrorCodeUnknown is a generic error that can be used as a last resort if there is no situation-specific error message that can be used
Functions ¶
func GetGroupNames ¶
func GetGroupNames() []string
GetGroupNames returns the list of Error group names that are registered
func ServeJSON ¶
func ServeJSON(w http.ResponseWriter, err error) error
ServeJSON attempts to serve the errcode in a JSON envelope. It marshals err and sets the content-type header to 'application/json'. It will handle ErrorCoder and Errors, and if necessary will create an envelope.
Types ¶
type Error ¶
type Error struct { Code ErrorCode `json:"code"` Message string `json:"message"` Detail interface{} `json:"detail,omitempty"` }
Error provides a wrapper around ErrorCode with extra Details provided.
func (Error) Error ¶
Error returns a human readable representation of the error.
func (Error) ErrorCode ¶
ErrorCode returns the ID/Value of this Error
func (Error) WithArgs ¶
WithArgs uses the passed-in list of interface{} as the substitution variables in the Error's Message string, but returns a new Error
type ErrorCode ¶
type ErrorCode int
ErrorCode represents the error type. The errors are serialized via strings and the integer format may change and should *never* be exported.
func ParseErrorCode ¶
ParseErrorCode returns the value by the string error code. `ErrorCodeUnknown` will be returned if the error is not known.
func Register ¶
func Register(group string, descriptor ErrorDescriptor) ErrorCode
Register will make the passed-in error known to the environment and return a new ErrorCode
func (ErrorCode) Descriptor ¶
func (ec ErrorCode) Descriptor() ErrorDescriptor
Descriptor returns the descriptor for the error code.
func (ErrorCode) ErrorCode ¶
ErrorCode just returns itself
func (ErrorCode) MarshalText ¶
MarshalText encodes the receiver into UTF-8-encoded text and returns the result.
func (ErrorCode) Message ¶
Message returned the human-readable error message for this error code.
func (ErrorCode) String ¶
String returns the canonical identifier for this error code.
func (*ErrorCode) UnmarshalText ¶
UnmarshalText decodes the form generated by MarshalText.
func (ErrorCode) WithArgs ¶
WithArgs creates a new Error struct and sets the Args slice
type ErrorCoder ¶
type ErrorCoder interface {
ErrorCode() ErrorCode
}
ErrorCoder is the base interface for ErrorCode and Error allowing users of each to just call ErrorCode to get the real ID of each
type ErrorDescriptor ¶
type ErrorDescriptor struct { // Code is the error code that this descriptor describes. Code ErrorCode // Value provides a unique, string key, often captilized with // underscores, to identify the error code. This value is used as the // keyed value when serializing api errors. Value string // Message is a short, human readable decription of the error condition // included in API responses. Message string // Description provides a complete account of the errors purpose, suitable // for use in documentation. Description string // HTTPStatusCode provides the http status code that is associated with // this error condition. HTTPStatusCode int }
ErrorDescriptor provides relevant information about a given error code.
func GetErrorAllDescriptors ¶
func GetErrorAllDescriptors() []ErrorDescriptor
GetErrorAllDescriptors returns a slice of all ErrorDescriptors that are registered, irrespective of what group they're in
func GetErrorCodeGroup ¶
func GetErrorCodeGroup(name string) []ErrorDescriptor
GetErrorCodeGroup returns the named group of error descriptors