44
55from fastapi import HTTPException
66
7- from backend .app .common .response .response_code import CodeEnum
7+ from backend .app .common .response .response_code import CustomCode
88
99
1010class BaseExceptionMixin (Exception ):
@@ -16,7 +16,14 @@ def __init__(self, *, msg: str = None, data: Any = None):
1616
1717
1818class 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 )
2027
2128
2229class RequestError (BaseExceptionMixin ):
@@ -54,21 +61,15 @@ def __init__(self, *, msg: str = 'Bad Gateway', data: Any = None):
5461 super ().__init__ (msg = msg , data = data )
5562
5663
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-
6364class AuthorizationError (BaseExceptionMixin ):
6465 code = 401
6566
6667 def __init__ (self , * , msg : str = 'Permission denied' , data : Any = None ):
6768 super ().__init__ (msg = msg , data = data )
6869
6970
70- class TokenError (BaseExceptionMixin ):
71+ class TokenError (HTTPError ):
7172 code = 401
7273
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