Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/flask_restx/errors.py: 55%
22 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:03 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:03 +0000
1import flask
3from werkzeug.exceptions import HTTPException
5from ._http import HTTPStatus
7__all__ = (
8 "abort",
9 "RestError",
10 "ValidationError",
11 "SpecsError",
12)
15def abort(code=HTTPStatus.INTERNAL_SERVER_ERROR, message=None, **kwargs):
16 """
17 Properly abort the current request.
19 Raise a `HTTPException` for the given status `code`.
20 Attach any keyword arguments to the exception for later processing.
22 :param int code: The associated HTTP status code
23 :param str message: An optional details message
24 :param kwargs: Any additional data to pass to the error payload
25 :raise HTTPException:
26 """
27 try:
28 flask.abort(code)
29 except HTTPException as e:
30 if message:
31 kwargs["message"] = str(message)
32 if kwargs:
33 e.data = kwargs
34 raise
37class RestError(Exception):
38 """Base class for all Flask-RESTX Errors"""
40 def __init__(self, msg):
41 self.msg = msg
43 def __str__(self):
44 return self.msg
47class ValidationError(RestError):
48 """A helper class for validation errors."""
50 pass
53class SpecsError(RestError):
54 """A helper class for incoherent specifications."""
56 pass