Documentation ¶
Overview ¶
Package errors implements errors defined in the Conjure specification.
Index ¶
- Variables
- func WriteErrorResponse(w http.ResponseWriter, e SerializableError)
- type Error
- func NewConflict(parameters ...Param) Error
- func NewError(errorType ErrorType, parameters ...Param) Error
- func NewFailedPrecondition(parameters ...Param) Error
- func NewInternal(parameters ...Param) Error
- func NewInvalidArgument(parameters ...Param) Error
- func NewNotFound(parameters ...Param) Error
- func NewPermissionDenied(parameters ...Param) Error
- func NewRequestEntityTooLarge(parameters ...Param) Error
- func NewTimeout(parameters ...Param) Error
- func UnpackError(se SerializableError) (e Error, err error)
- type ErrorCode
- type ErrorType
- type Param
- type SerializableError
Constants ¶
This section is empty.
Variables ¶
var ( DefaultPermissionDenied = ErrorType{PermissionDenied, "Default:PermissionDenied"} DefaultInvalidArgument = ErrorType{InvalidArgument, "Default:InvalidArgument"} DefaultNotFound = ErrorType{NotFound, "Default:NotFound"} DefaultConflict = ErrorType{Conflict, "Default:Conflict"} DefaultRequestEntityTooLarge = ErrorType{RequestEntityTooLarge, "Default:RequestEntityTooLarge"} DefaultFailedPrecondition = ErrorType{FailedPrecondition, "Default:FailedPrecondition"} DefaultInternal = ErrorType{Internal, "Default:Internal"} DefaultTimeout = ErrorType{Timeout, "Default:Timeout"} )
Functions ¶
func WriteErrorResponse ¶
func WriteErrorResponse(w http.ResponseWriter, e SerializableError)
WriteErrorResponse writes error to the response writer.
TODO This function is subject to change.
Types ¶
type Error ¶
type Error interface { error // Code returns an enum describing error category. Code() ErrorCode // Name returns an error name identifying error type. Name() string // InstanceID returns unique identifier of this particular error instance. InstanceID() uuid.UUID // Parameters returns a set of named parameters detailing this particular error instance, // for example error message. Parameters() map[string]interface{} }
Error is an error intended for transport through RPC channels such as HTTP responses.
Error is represented by its error code, an error name identifying the type of error and an optional set of named parameters detailing the error.
func NewConflict ¶
NewConflict returns new error instance of default conflict type.
func NewError ¶
NewError returns new instance of an error of the specified type with provided parameters.
func NewFailedPrecondition ¶
NewFailedPrecondition returns new error instance of default failed precondition type.
func NewInternal ¶
NewInternal returns new error instance of default internal type.
func NewInvalidArgument ¶
NewInvalidArgument returns new error instance of default invalid argument type.
func NewNotFound ¶
NewNotFound returns new error instance of default not found type.
func NewPermissionDenied ¶
NewPermissionDenied returns new error instance of default permission denied type.
func NewRequestEntityTooLarge ¶
NewRequestEntityTooLarge returns new error instance of default request entity too large type.
func NewTimeout ¶
NewTimeout returns new error instance of default timeout type.
func UnpackError ¶
func UnpackError(se SerializableError) (e Error, err error)
UnpackError recreates an error instance from the given serializable error.
type ErrorCode ¶
type ErrorCode int16
ErrorCode is an enum describing error category.
Each error code has associated HTTP status codes.
const ( // PermissionDenied has status code 403 Forbidden. PermissionDenied ErrorCode // InvalidArgument has status code 400 BadRequest. InvalidArgument // NotFound has status code 404 NotFound. NotFound // Conflict has status code 409 Conflict. Conflict // RequestEntityTooLarge has status code 413 RequestEntityTooLarge. RequestEntityTooLarge // FailedPrecondition has status code 500 InternalServerError. FailedPrecondition // Internal has status code 500 InternalServerError. Internal // Timeout has status code 500 InternalServerError. Timeout // CustomClient has status code 400 BadRequest. CustomClient // CustomServer has status code 500 InternalServerError. CustomServer )
func (ErrorCode) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (ErrorCode) StatusCode ¶
StatusCode returns HTTP status code associated with this error code.
func (ErrorCode) String ¶
String representation of this error code.
For example "NOT_FOUND", "CONFLICT", "PERMISSION_DENIED" or "TIMEOUT".
func (*ErrorCode) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type ErrorType ¶
type ErrorType struct {
// contains filtered or unexported fields
}
ErrorType represents certain class of errors. Each error type is uniquely identified by an error name and has assigned one of possible error codes.
Error type should be a compile-time constant and is considered part of the API of a service that produces error of such type.
func MustErrorType ¶
MustErrorType is panicking equivalent of NewErrorType.
func NewErrorType ¶
NewErrorType returns error type with the provided error code and name, or returns an error if error of such type cannot be created.
Error name must be in the "PascalCase:PascalCase" format, for example "Default:PermissionDenied", "Facebook:LikeAlreadyGiven" or "MyApplication:ErrorSpecificToMyBusinessDomain". The first part of an error name is a namespace and the second part contains cause on an error. "Default" namespace is reserved for error types defined in this package.
For example:
var ErrorLikeAlreadyGiven = errors.MustErrorType( errors.ErrorCodeConflict, "Facebook:LikeAlreadyGiven", )
type Param ¶
type Param interface {
// contains filtered or unexported methods
}
Param represents error parameter.
func UnsafeParam ¶
UnsafeParam creates unsafe error parameter with the given key and value.
type SerializableError ¶
type SerializableError struct { ErrorCode ErrorCode `json:"errorCode"` ErrorName string `json:"errorName"` ErrorInstanceID uuid.UUID `json:"errorInstanceId"` Parameters json.RawMessage `json:"parameters,omitempty"` }
SerializableError is serializable representation of an error, it includes error code, name, instance id and parameters. It can be used to implement error marshalling & unmarshalling of concrete types implementing an Error interface.
This type does not marshall & unmarshall parameters - that should be responsibility of a type implementing an Error.
This is an example of a valid JSON object representing an error:
{ "errorCode": "CONFLICT", "errorName": "Facebook:LikeAlreadyGiven", "errorInstanceId": "00010203-0405-0607-0809-0a0b0c0d0e0f", "parameters": { "postId": "5aa734gs3579", "userId": 642764872364 } }
func ErrorFromResponse ¶
func ErrorFromResponse(response *http.Response) (SerializableError, error)
ErrorFromResponse extract serializable error from the given response.
TODO This function is subject to change.