Documentation ¶
Overview ¶
Package usererrors marshals and unmarshals structured errors bound for the end user of a service. It provides an interface for registering custom error types in addition to a set of common basic errors.
Custom errors must conform to the UserError interface and should call Register in the init function of the package in which they are defined. The Code returned by the error must be unique across the application and any packages it imports. The Message returned should be a complete and properly puntuated sentence that can be displayed directly to the user. It should be generated exclusively from the contents of the error type, not provided by the caller. The provides the client the option of either displaying the generated error message directly to the end user or generating a custom message.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalJSON ¶
MarshalJSON encodes the UserError as JSON. If the provided value is an array, map, slice or struct with at least one field it is marshalled into the `data` field.
Types ¶
type ActionNotAllowed ¶
type ActionNotAllowed struct {
Action string `json:"action"`
}
ActionNotAllowed describes an action that is not permitted.
func (ActionNotAllowed) Code ¶
func (e ActionNotAllowed) Code() string
Code returns "action_not_allowed"
func (ActionNotAllowed) Message ¶
func (e ActionNotAllowed) Message() string
Message returns a string describing the disallowed action
type AuthInvalid ¶
type AuthInvalid struct{}
AuthInvalid indicates that the authorization you provided is invalid.
func (AuthInvalid) Message ¶
func (e AuthInvalid) Message() string
Message returns a generic unauthorized message.
type InternalFailure ¶
type InternalFailure struct{}
InternalFailure represents a prviate internal error.
func (InternalFailure) Code ¶
func (e InternalFailure) Code() string
Code returns "internal_failure"
func (InternalFailure) Message ¶
func (e InternalFailure) Message() string
Message returns a generic internal error message
type InvalidParams ¶
type InvalidParams []InvalidParamsEntry
InvalidParams represents a list of parameter validation errors. Each element in the list contains an explanation of the error and a list of the parameters that failed.
func (InvalidParams) Message ¶
func (e InvalidParams) Message() string
Message returns a joined representation of parameter messages. When possible, the underlying data should be used instead to separate errors by parameter.
type InvalidParamsEntry ¶
InvalidParamsEntry represents a single error for InvalidParams
type NotFound ¶
type NotFound struct{}
NotFound indicates that the requested resource could not be found.
type UserError ¶
UserError represents an error that can be returned to the client. UserErrors should be instantiated at the package-level with constant error strings.
func UnmarshalJSON ¶
UnmarshalJSON parses a JSON-encoded UserError. If the code of the error has been registered, the registered type is returned.