-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
38 lines (29 loc) · 1.04 KB
/
errors.py
File metadata and controls
38 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from fastapi.responses import JSONResponse
class BaseErrResp(Exception):
def __init__(self, status: int, title: str, details: list) -> None:
self.__status = status
self.__title = title
self.__detail = details
def gen_err_resp(self) -> JSONResponse:
return JSONResponse(
status_code=self.__status,
content={
"type": "about:blank",
'title': self.__title,
'status': self.__status,
'detail': self.__detail
}
)
class BadRequest(BaseErrResp):
def __init__(self, details: list):
super(BadRequest, self).__init__(400, 'Bad Request', details)
class InternalError(BaseErrResp):
def __init__(self, details: list):
super(InternalError, self).__init__(500, 'Internal Error', details)
class UnprocessableError(BaseErrResp):
def __init__(self, details: list):
super(UnprocessableError, self).__init__(
422,
'Unprocessable Entity',
details
)