Errors¶
-
cliquet.errors.
ERRORS
¶ Predefined errors as specified by the protocol.
status code errno description 401 104 Missing Authorization Token 401 105 Invalid Authorization Token 400 106 request body was not valid JSON 400 107 invalid request parameter 400 108 missing request parameter 400 109 invalid posted data 404 110 Invalid Token / id 404 111 Missing Token / id 411 112 Content-Length header was not provided 413 113 Request body too large 412 114 Resource was modified meanwhile 405 115 Method not allowed on this end point 404 116 Requested version not available on this server 429 117 Client has sent too many requests 403 121 Resource’s access forbidden for this user 409 122 Another resource violates constraint 500 999 Internal Server Error 503 201 Service Temporary unavailable due to high load 410 202 Service deprecated alias of
Enum
-
cliquet.errors.
http_error
(httpexception, errno=None, code=None, error=None, message=None, info=None, details=None)¶ Return a JSON formated response matching the error protocol.
Parameters: - httpexception – Instance of
httpexceptions
- errno – stable application-level error number (e.g. 109)
- code – matches the HTTP status code (e.g 400)
- error – string description of error type (e.g. “Bad request”)
- message – context information (e.g. “Invalid request parameters”)
- info – information about error (e.g. URL to troubleshooting)
- details – additional structured details (conflicting record)
Returns: the formatted response object
Return type: - httpexception – Instance of
-
cliquet.errors.
json_error_handler
(errors)¶ Cornice JSON error handler, returning consistant JSON formatted errors from schema validation errors.
This is meant to be used is custom services in your applications.
upload = Service(name="upload", path='/upload', error_handler=errors.json_error_handler)
Warning
Only the first error of the list is formatted in the response. (c.f. protocol).
-
cliquet.errors.
raise_invalid
(request, location='body', name=None, description=None, **kwargs)¶ Helper to raise a validation error.
Parameters: - location – location in request (e.g.
'querystring'
) - name – field name
- description – detailed description of validation error
Raises: - location – location in request (e.g.
-
cliquet.errors.
send_alert
(request, message=None, url=None, code='soft-eol')¶ Helper to add an Alert header to the response.
Parameters: - code – The type of error ‘soft-eol’, ‘hard-eol’
- message – The description message.
- url – The URL for more information, default to the documentation url.