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 23
23
app .include_router (api .api_router )
24
24
25
25
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 ):
28
28
return JSONResponse (
29
29
status_code = exc .status_code ,
30
30
content = {'detail' : exc .message },
Original file line number Diff line number Diff line change 3
3
"""
4
4
5
5
6
- class BaseException (Exception ):
6
+ class CustomException (Exception ):
7
7
def __init__ (self , message : str , status_code : int = 500 ):
8
8
super ().__init__ (message )
9
9
self .message = message
10
10
self .status_code = status_code
11
11
12
12
13
13
# Users
14
- class UserExistsException (BaseException ):
14
+ class UserExistsException (CustomException ):
15
15
def __init__ (self ):
16
16
super ().__init__ ('User is already taken.' , status_code = 409 )
17
17
18
18
19
- class UserNotFoundException (BaseException ):
19
+ class UserNotFoundException (CustomException ):
20
20
def __init__ (self ):
21
21
super ().__init__ ('User not found.' , status_code = 404 )
22
22
23
23
24
- class UserIsCorrectException (BaseException ):
24
+ class UserIsCorrectException (CustomException ):
25
25
def __init__ (self ):
26
26
super ().__init__ ('User is correct.' , status_code = 401 )
27
27
28
28
29
29
# Tokens
30
- class TokenInvalidException (BaseException ):
30
+ class TokenInvalidException (CustomException ):
31
31
def __init__ (self ):
32
32
super ().__init__ ('Invalid token.' , status_code = 401 )
33
33
34
34
35
- class TokenExpiredException (BaseException ):
35
+ class TokenExpiredException (CustomException ):
36
36
def __init__ (self ):
37
37
super ().__init__ ('Token expired.' , status_code = 401 )
You can’t perform that action at this time.
0 commit comments