4
4
5
5
from fastapi import HTTPException
6
6
7
- from backend .app .common .response .response_code import CodeEnum
7
+ from backend .app .common .response .response_code import CustomCode
8
8
9
9
10
10
class BaseExceptionMixin (Exception ):
@@ -16,7 +16,14 @@ def __init__(self, *, msg: str = None, data: Any = None):
16
16
17
17
18
18
class HTTPError (HTTPException ):
19
- pass
19
+ def __init__ (self , * , code : int , msg : Any = None , headers : dict [str , Any ] | None = None ):
20
+ super ().__init__ (status_code = code , detail = msg , headers = headers )
21
+
22
+
23
+ class CustomError (BaseExceptionMixin ):
24
+ def __init__ (self , * , error : CustomCode , data : Any = None ):
25
+ self .code = error .code
26
+ super ().__init__ (msg = error .msg , data = data )
20
27
21
28
22
29
class RequestError (BaseExceptionMixin ):
@@ -54,21 +61,15 @@ def __init__(self, *, msg: str = 'Bad Gateway', data: Any = None):
54
61
super ().__init__ (msg = msg , data = data )
55
62
56
63
57
- class CodeError (BaseExceptionMixin ):
58
- def __init__ (self , * , error : CodeEnum , data : Any = None ):
59
- self .code = error .code
60
- super ().__init__ (msg = error .msg , data = data )
61
-
62
-
63
64
class AuthorizationError (BaseExceptionMixin ):
64
65
code = 401
65
66
66
67
def __init__ (self , * , msg : str = 'Permission denied' , data : Any = None ):
67
68
super ().__init__ (msg = msg , data = data )
68
69
69
70
70
- class TokenError (BaseExceptionMixin ):
71
+ class TokenError (HTTPError ):
71
72
code = 401
72
73
73
- def __init__ (self , * , msg : str = 'Token is invalid ' , data : Any = None ):
74
- super ().__init__ (msg = msg , data = data )
74
+ def __init__ (self , * , msg : str = 'Not authenticated ' , headers : dict [ str , Any ] | None = None ):
75
+ super ().__init__ (code = self . code , msg = msg , headers = headers or { 'WWW-Authenticate' : 'Bearer' } )
0 commit comments