-
Notifications
You must be signed in to change notification settings - Fork 0
/
exceptions.py
58 lines (42 loc) · 1.37 KB
/
exceptions.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from fastapi import HTTPException
from starlette import status
def HTTP_400(msg: str = "one or more field is not present") -> HTTPException:
return HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=msg
)
def HTTP_403(msg: str = "Forbidden") -> HTTPException:
return HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=msg
)
def HTTP_409(msg: str = "Data already exist") -> HTTPException:
return HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=msg
)
def HTTP_422(msg: str = "Unprocessable Entity") -> HTTPException:
return HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail=msg
)
def HTTP_401(msg: str = "UnAuthorized") -> HTTPException:
return HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=msg
)
def HTTP_404(msg: str = "Not found") -> HTTPException:
return HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=msg
)
def HTTP_500(msg: str = "Internal Server ERROR") -> HTTPException:
return HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=msg
)
def HTTP_503(msg: str = "Service Unavailable") -> HTTPException:
return HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail=msg
)