Documentation ¶
Overview ¶
Package merr is Misakey Error package, it help us to meet contracted error format defined in our convention it also allow us to define error code linked to our domain that would never change and will be used by consumers
Index ¶
- Constants
- Variables
- func AddCodeToURL(req string, code Code) (string, error)
- func Cause(err error) error
- func IsAConflict(err error) bool
- func IsAForbidden(err error) bool
- func IsANotFound(err error) bool
- func IsAnInternal(err error) bool
- func IsUnauthorized(err error) bool
- func ToHTTPCode(err error) int
- type Code
- type Error
- func BadGateway() Error
- func BadRequest() Error
- func ClientClosedRequest() Error
- func Conflict() Error
- func Forbidden() Error
- func From(err error) Error
- func FromHTTPCode(code int) Error
- func Gone() Error
- func HandleErr(err error) (int, Error)
- func Internal() Error
- func MethodNotAllowed() Error
- func NotFound() Error
- func RequestEntityTooLarge() Error
- func ServiceUnavailable() Error
- func Unauthorized() Error
- func UnprocessableEntity() Error
- func UnsupportedMediaType() Error
- func (e Error) Add(k string, v string) Error
- func (e *Error) Cause() error
- func (e Error) Code(c Code) Error
- func (e Error) Desc(desc string) Error
- func (e Error) Descf(desc string, a ...interface{}) Error
- func (e Error) End() Error
- func (e Error) Error() string
- func (e Error) Flush() Error
- func (e Error) Ori(ori Origin) Error
- type Origin
Constants ¶
const ( DVConflict string = "conflict" // unique... DVMalformed string = "malformed" // email format, ip address format... DVInvalid string = "invalid" // minimum/maximum value/length... DVRequired string = "required" // missing in request... DVExpired string = "expired" // expired duration... DVForbidden string = "forbidden" // forbidden to update... DVInternal string = "internal" // internal error occurred DVLocked string = "locked" // cannot be updated DVNotFound string = "not_found" // correspondance has not been found DVNotSupported string = "not_supported" // not handled by the running implementation DVTimedOut string = "timed_out" // something... timed out DVUnknown string = "unknown" // unknown detail code DVNoCode string = "no_code" // no specific code )
detail constants
Variables ¶
var ( // ErrBadRequest ... ErrBadRequest = errors.New("bad request") ErrUnauthorized = errors.New("not authorized") // ErrForbidden ... ErrForbidden = errors.New("forbidden") // ErrNotFound ... ErrNotFound = errors.New("not found") // ErrMethodNotAllowed ... ErrMethodNotAllowed = errors.New("method not allowed") // ErrConflict ... ErrConflict = errors.New("conflict") // ErrGone ... ErrGone = errors.New("gone") // UnsupportedMediaType ... ErrUnsupportedMediaType = errors.New("unsupported media type") // ErrRequestEntityTooLarge ... ErrRequestEntityTooLarge = errors.New("request entity too large") // ErrUnprocessableEntity ... ErrUnprocessableEntity = errors.New("unprocessable entity") // ErrClientClosedRequest ... ErrClientClosedRequest = errors.New("client closed request") // ErrBadGateway ... ErrBadGateway = errors.New("bad gateway") ErrServiceUnavailable = errors.New("service unavailable") // ErrInternal ... ErrInternal = errors.New("internal server") )
Declares some classic errors as variables to use it as a base for our error system
var ( // StatusClientClosedRequest shall never be returned to consumer because of the context of the code StatusClientClosedRequest = 499 // http://lxr.nginx.org/source/src/http/ngx_http_request.h#0120 )
Functions ¶
func AddCodeToURL ¶
AddCodeToURL takes a request and adds a merr.Code to it as a query params
func Cause ¶
Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:
type causer interface { Cause() error }
If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.
Types ¶
type Code ¶
type Code string
Code describes an error code as a string used internally and by clearer consumer for better error identifications & reactions. It represents global codes and corresponds to http status as described [here](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes). We use this link as general specifications for errors and not just for http request errors.
const ( // classic codes BadRequestCode Code = "bad_request" ForbiddenCode Code = "forbidden" NotFoundCode Code = "not_found" MethodNotAllowedCode Code = "method_not_allowed" ConflictCode Code = "conflict" GoneCode Code = "gone" RequestEntityTooLargeCode Code = "request_entity_too_large" UnsupportedMediaTypeCode Code = "unsupported_media_type_code" UnprocessableEntityCode Code = "unprocessable_entity" ClientClosedRequestCode Code = "client_closed_requiest" InternalCode Code = "internal" BadGatewayCode Code = "bad_gateway" // no_code codes UnknownCode Code = "unknown_code" NoCodeCode Code = "no_code" // redirect codes AuthProcessRequiredCode Code = "auth_process_required" ConsentRequiredCode Code = "consent_required" LoginRequiredCode Code = "login_required" InvalidFlowCode Code = "invalid_flow" MissingParameter Code = "missing_parameter" )
code constants
func ToCode ¶
ToCode takes a default error and return corresponding Code
type Error ¶
type Error struct { Co Code `json:"code"` Origin Origin `json:"origin"` Description string `json:"desc"` Details map[string]string `json:"details"` // contains filtered or unexported fields }
Error defines internal errors type we deal with in misakey domain layers
func FromHTTPCode ¶
FromHTTPCode returns merr corresponding to HTTP code
func HandleErr ¶
HandleErr tries to interpret an error as a Misakey Error returning HTTTP Code aside it. Its set default value if the error is not a Misakey Error
func (Error) Add ¶
Add a key/value detail to the error Details map
func (*Error) Cause ¶
Cause returns the raw error contained within Error
func (Error) Desc ¶
Desc the Error (concat with existing one)
func (Error) Descf ¶
Descfribe the Error using Sprintf (concat with existing one)
func (Error) End ¶
End triggers the end of a If method - unfreeze updates of the Error.
type Origin ¶
type Origin string
Origin is an information about where the error does come from. Once set, the Origin of an error should not be spoiled.
const ( OriACR Origin = "acr" // the error comes from the authorization token acr OriBody Origin = "body" // the error comes from body parameter OriHeaders Origin = "headers" // the error comes from headers OriQuery Origin = "query" // the error comes from query parameters OriPath Origin = "path" // the error comes from path parameters OriCookies Origin = "cookies" // the error comes from cookies OriNotDefined Origin = "not_defined" // the error has no origin defined yet )
origin constants