Documentation ¶
Overview ¶
Package errors implements errors defined in the Conjure specification.
Index ¶
- Variables
- func IsConflict(err error) bool
- func IsFailedPrecondition(err error) bool
- func IsInternal(err error) bool
- func IsInvalidArgument(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDenied(err error) bool
- func IsRequestEntityTooLarge(err error) bool
- func IsTimeout(err error) bool
- func IsUnauthorized(err error) bool
- func NewWrappedError(conjureErr Error, err error) error
- func RegisterErrorType(name string, typ reflect.Type)
- func WriteErrorResponse(w http.ResponseWriter, e Error)
- type Error
- func GetConjureError(err error) Error
- func NewConflict(parameters ...wparams.ParamStorer) Error
- func NewError(errorType ErrorType, parameters ...wparams.ParamStorer) Error
- func NewFailedPrecondition(parameters ...wparams.ParamStorer) Error
- func NewInternal(parameters ...wparams.ParamStorer) Error
- func NewInvalidArgument(parameters ...wparams.ParamStorer) Error
- func NewNotFound(parameters ...wparams.ParamStorer) Error
- func NewPermissionDenied(parameters ...wparams.ParamStorer) Error
- func NewRequestEntityTooLarge(parameters ...wparams.ParamStorer) Error
- func NewTimeout(parameters ...wparams.ParamStorer) Error
- func NewUnauthorized(parameters ...wparams.ParamStorer) Error
- func UnmarshalError(body []byte) (Error, error)
- func WrapWithConflict(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithFailedPrecondition(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithInternal(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithInvalidArgument(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithNewError(cause error, errorType ErrorType, parameters ...wparams.ParamStorer) Error
- func WrapWithNotFound(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithPermissionDenied(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithRequestEntityTooLarge(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithTimeout(cause error, parameters ...wparams.ParamStorer) Error
- func WrapWithUnauthorized(cause error, parameters ...wparams.ParamStorer) Error
- type ErrorCode
- type ErrorType
- type SerializableError
Constants ¶
This section is empty.
Variables ¶
var ( DefaultPermissionDenied = ErrorType{PermissionDenied, errorNamePermissionDenied} DefaultInvalidArgument = ErrorType{InvalidArgument, errorNameInvalidArgument} DefaultNotFound = ErrorType{NotFound, errorNameNotFound} DefaultConflict = ErrorType{Conflict, errorNameConflict} DefaultRequestEntityTooLarge = ErrorType{RequestEntityTooLarge, errorNameRequestEntityTooLarge} DefaultFailedPrecondition = ErrorType{FailedPrecondition, errorNameFailedPrecondition} DefaultInternal = ErrorType{Internal, errorNameInternal} DefaultTimeout = ErrorType{Timeout, errorNameTimeout} )
Functions ¶
func IsConflict ¶ added in v2.27.0
IsConflict returns true if an error is an instance of default conflict type.
func IsFailedPrecondition ¶ added in v2.27.0
IsFailedPrecondition returns true if an error is an instance of default failed precondition type.
func IsInternal ¶ added in v2.27.0
IsInternal returns true if an error is an instance of default internal type.
func IsInvalidArgument ¶ added in v2.27.0
IsInvalidArgument returns true if an error is an instance of default invalid argument type.
func IsNotFound ¶ added in v2.27.0
IsNotFound returns true if an error is an instance of default not found type.
func IsPermissionDenied ¶ added in v2.27.0
IsPermissionDenied returns true if an error is an instance of default permission denied type.
func IsRequestEntityTooLarge ¶ added in v2.27.0
IsRequestEntityTooLarge returns true if an error is an instance of default request entity too large type.
func IsTimeout ¶ added in v2.27.0
IsTimeout returns true if an error is an instance of default timeout type.
func IsUnauthorized ¶ added in v2.27.0
IsUnauthorized returns true if an error is an instance of default unauthorized type.
func NewWrappedError ¶ added in v2.1.0
NewWrappedError is a convenience function for adding an underlying error to a conjure error as additional context. This exists so that the conjure error becomes the RootCause, which is used to extract the conjure error for serialization when returned by a server handler.
The conjure error is wrapped using err's Error() message, and params if ParamStorer is implemented. All other context is discarded, including cause stack (i.e. stacktrace) and type information.
DEPRECATED: Use WrapWithNewError for generic errors or WrapWithMyErrorType for conjure-generated errors.
func RegisterErrorType ¶
RegisterErrorType registers an error name and its go type in a global registry. The type should be a struct type whose pointer implements Error. Panics if name is already registered or *type does not implement Error.
func WriteErrorResponse ¶
func WriteErrorResponse(w http.ResponseWriter, e Error)
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 wparams.ParamStorer }
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 GetConjureError ¶ added in v2.4.0
GetConjureError recursively searches for an error of type Error in a chain of causes. It returns the first instance that it finds, or nil if one is not found.
func NewConflict ¶
func NewConflict(parameters ...wparams.ParamStorer) Error
NewConflict returns new error instance of default conflict type.
func NewError ¶
func NewError(errorType ErrorType, parameters ...wparams.ParamStorer) Error
NewError returns new instance of an error of the specified type with provided parameters.
func NewFailedPrecondition ¶
func NewFailedPrecondition(parameters ...wparams.ParamStorer) Error
NewFailedPrecondition returns new error instance of default failed precondition type.
func NewInternal ¶
func NewInternal(parameters ...wparams.ParamStorer) Error
NewInternal returns new error instance of default internal type.
func NewInvalidArgument ¶
func NewInvalidArgument(parameters ...wparams.ParamStorer) Error
NewInvalidArgument returns new error instance of default invalid argument type.
func NewNotFound ¶
func NewNotFound(parameters ...wparams.ParamStorer) Error
NewNotFound returns new error instance of default not found type.
func NewPermissionDenied ¶
func NewPermissionDenied(parameters ...wparams.ParamStorer) Error
NewPermissionDenied returns new error instance of default permission denied type.
func NewRequestEntityTooLarge ¶
func NewRequestEntityTooLarge(parameters ...wparams.ParamStorer) Error
NewRequestEntityTooLarge returns new error instance of default request entity too large type.
func NewTimeout ¶
func NewTimeout(parameters ...wparams.ParamStorer) Error
NewTimeout returns new error instance of default timeout type.
func NewUnauthorized ¶ added in v2.21.0
func NewUnauthorized(parameters ...wparams.ParamStorer) Error
NewUnauthorized returns new error instance of default unauthorized type.
func UnmarshalError ¶
UnmarshalError attempts to deserialize the message to a known implementation of Error. Custom error types should be registered using RegisterErrorType. If the ErrorName is not recognized, a genericError is returned with all params marked unsafe. If we fail to unmarshal to a generic SerializableError or to the type specified by ErrorName, an error is returned.
func WrapWithConflict ¶ added in v2.4.0
func WrapWithConflict(cause error, parameters ...wparams.ParamStorer) Error
WrapWithConflict returns new error instance of default conflict type wrapping an existing error.
func WrapWithFailedPrecondition ¶ added in v2.4.0
func WrapWithFailedPrecondition(cause error, parameters ...wparams.ParamStorer) Error
WrapWithFailedPrecondition returns new error instance of default failed precondition type wrapping an existing error.
func WrapWithInternal ¶ added in v2.4.0
func WrapWithInternal(cause error, parameters ...wparams.ParamStorer) Error
WrapWithInternal returns new error instance of default internal type wrapping an existing error.
func WrapWithInvalidArgument ¶ added in v2.4.0
func WrapWithInvalidArgument(cause error, parameters ...wparams.ParamStorer) Error
WrapWithInvalidArgument returns new error instance of default invalid argument type wrapping an existing error.
func WrapWithNewError ¶ added in v2.4.0
func WrapWithNewError(cause error, errorType ErrorType, parameters ...wparams.ParamStorer) Error
WrapWithNewError returns new instance of an error of the specified type with provided parameters wrapping an existing error.
func WrapWithNotFound ¶ added in v2.4.0
func WrapWithNotFound(cause error, parameters ...wparams.ParamStorer) Error
WrapWithNotFound returns new error instance of default not found type wrapping an existing error.
func WrapWithPermissionDenied ¶ added in v2.4.0
func WrapWithPermissionDenied(cause error, parameters ...wparams.ParamStorer) Error
WrapWithPermissionDenied returns new error instance of default permission denied type wrapping an existing error.
func WrapWithRequestEntityTooLarge ¶ added in v2.4.0
func WrapWithRequestEntityTooLarge(cause error, parameters ...wparams.ParamStorer) Error
WrapWithRequestEntityTooLarge returns new error instance of default request entity too large type wrapping an existing error.
func WrapWithTimeout ¶ added in v2.4.0
func WrapWithTimeout(cause error, parameters ...wparams.ParamStorer) Error
WrapWithTimeout returns new error instance of default timeout type wrapping an existing error.
func WrapWithUnauthorized ¶ added in v2.21.0
func WrapWithUnauthorized(cause error, parameters ...wparams.ParamStorer) Error
WrapWithUnauthorized returns new error instance of default unauthorized type wrapping an existing 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 // 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 )Unauthorized ErrorCode
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 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 marshaling & unmarshaling of concrete types implementing an Error interface.
This type does not marshal & unmarshal 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 } }