Documentation ¶
Overview ¶
TO COPY - TO ADAPT merror 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 HasCode(err error, code Code) 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 Gone() Error
- func HandleErr(err error) (int, Error)
- func Internal() Error
- func MethodNotAllowed() Error
- func NotFound() Error
- func RequestEntityTooLarge() Error
- func ServiceUnavailable() Error
- func Transform(err error) Error
- func TransformHTTPCode(code int) Error
- func Unauthorized() Error
- func UnprocessableEntity() Error
- func (e *Error) Cause() error
- func (e *Error) Clear() bool
- func (e Error) Code(c Code) Error
- func (e Error) Describe(desc string) Error
- func (e Error) Describef(desc string, a ...interface{}) Error
- func (e Error) Detail(k string, v string) Error
- func (e Error) End() Error
- func (e Error) Error() string
- func (e Error) Flush() Error
- func (e Error) FlushDesc() Error
- func (e Error) From(ori Origin) Error
- func (e Error) If(match error) Error
- func (e Error) ResetDetails() Error
- type Origin
Constants ¶
const ( DVConflict string = "conflict" // unique... DVMalformed string = "malformed" // email format, ip address format... DVInvalid string = "invalid" // minumum/maximum value/lenght... DVRequired string = "required" // missing in request... DVExpired string = "expired" // expired duration... DVForbidden string = "forbidden" // forbidden to update... DVInternal string = "internal" // internal error occured 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 )
Variables ¶
var ( BadRequestError = errors.New("bad request") ForbiddenError = errors.New("forbidden") NotFoundError = errors.New("not found") MethodNotAllowedError = errors.New("method not allowed") ConflictError = errors.New("conflict") GoneError = errors.New("gone") RequestEntityTooLargeError = errors.New("request entity too large") UnprocessableEntityError = errors.New("unprocessable entity") ClientClosedRequestError = errors.New("client closed request") BadGatewayError = errors.New("bad gateway") InternalError = errors.New("internal server") )
Declares some classic errors as variables to use it as a base for our error system
var ( // 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 merror.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.
func ToHTTPCode ¶
Conversion function from Misakey Error to HTTP and vice-versa. ToCode returns HTTP code corresponding to Domain Misakey Code
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" // 400 general bad request ForbiddenCode Code = "forbidden" // 403 accesses checks failed NotFoundCode Code = "not_found" // 404 the resource/route has been not found MethodNotAllowedCode Code = "method_not_allowed" // 405 the method is not supported at a resource ConflictCode Code = "conflict" // 409 the action cannot be perform of the resource GoneCode Code = "gone" // 410 ressource does not exist any more RequestEntityTooLargeCode Code = "request_entity_too_large" // 413 the requested entity is too large UnprocessableEntityCode Code = "unprocessable_entity" // 422 the received entity is unprocessable ClientClosedRequestCode Code = "client_closed_requiest" // 499 client closed the request so context has been canceled InternalCode Code = "internal" // 500 something internal to the service has failed BadGatewayCode Code = "bad_gateway" // 502 invalid response from the server // no_code codes UnknownCode Code = "unknown_code" // 500 something internal to the service has failed NoCodeCode Code = "no_code" // xxx no specific code defined // redirect codes AuthProcessRequiredCode Code = "auth_process_required" ConsentRequiredCode Code = "consent_required" LoginRequiredCode Code = "login_required" InvalidFlowCode Code = "invalid_flow" MissingParameter Code = "missing_parameter" )
type Error ¶
type Error struct { Co Code `json:"code"` Ori Origin `json:"origin"` Desc 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 BadGateway ¶ added in v1.7.0
func BadGateway() Error
func BadRequest ¶
func BadRequest() Error
func ClientClosedRequest ¶
func ClientClosedRequest() Error
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 MethodNotAllowed ¶
func MethodNotAllowed() Error
func RequestEntityTooLarge ¶
func RequestEntityTooLarge() Error
func ServiceUnavailable ¶ added in v1.4.0
func ServiceUnavailable() Error
func TransformHTTPCode ¶
Transform returns merror corresponding to HTTP code
func Unauthorized ¶
func Unauthorized() Error
func UnprocessableEntity ¶
func UnprocessableEntity() 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 OriInternal Origin = "internal" // the error comes from internal logic OriQuery Origin = "query" // the error comes from query parameters OriPath Origin = "path" // the error comes from path parameters OriNotDefined Origin = "not_defined" // the error has no origin defined yet )