File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed
Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 2323app .include_router (api .api_router )
2424
2525
26- @app .exception_handler (exps .BaseException )
27- async def exception_handler (request , exc : exps .BaseException ):
26+ @app .exception_handler (exps .CustomException )
27+ async def exception_handler (request , exc : exps .CustomException ):
2828 return JSONResponse (
2929 status_code = exc .status_code ,
3030 content = {'detail' : exc .message },
Original file line number Diff line number Diff line change 33"""
44
55
6- class BaseException (Exception ):
6+ class CustomException (Exception ):
77 def __init__ (self , message : str , status_code : int = 500 ):
88 super ().__init__ (message )
99 self .message = message
1010 self .status_code = status_code
1111
1212
1313# Users
14- class UserExistsException (BaseException ):
14+ class UserExistsException (CustomException ):
1515 def __init__ (self ):
1616 super ().__init__ ('User is already taken.' , status_code = 409 )
1717
1818
19- class UserNotFoundException (BaseException ):
19+ class UserNotFoundException (CustomException ):
2020 def __init__ (self ):
2121 super ().__init__ ('User not found.' , status_code = 404 )
2222
2323
24- class UserIsCorrectException (BaseException ):
24+ class UserIsCorrectException (CustomException ):
2525 def __init__ (self ):
2626 super ().__init__ ('User is correct.' , status_code = 401 )
2727
2828
2929# Tokens
30- class TokenInvalidException (BaseException ):
30+ class TokenInvalidException (CustomException ):
3131 def __init__ (self ):
3232 super ().__init__ ('Invalid token.' , status_code = 401 )
3333
3434
35- class TokenExpiredException (BaseException ):
35+ class TokenExpiredException (CustomException ):
3636 def __init__ (self ):
3737 super ().__init__ ('Token expired.' , status_code = 401 )
You can’t perform that action at this time.
0 commit comments