File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212async def find_user_by_username_email (
1313 db : AsyncDatabase , username : str , email : str
1414) -> Optional [UserAuthOut ]:
15- try :
16- user_auth = await db .user_auth .find_one (
17- {"$or" : [{"username" : username }, {"email" : email }]}
18- )
19- if not user_auth :
20- return None
21-
22- return UserAuthOut (** user_auth )
15+ user_auth = await db .user_auth .find_one (
16+ {"$or" : [{"username" : username }, {"email" : email }]}
17+ )
18+ if not user_auth :
19+ return None
2320
24- except PyMongoError as e :
25- logger .critical (f"Failed to query db for user returning error: { e } " )
26- raise InternalServerError ()
21+ return UserAuthOut (** user_auth )
2722
2823
2924async def create_user (db : AsyncDatabase , user : UserRegistration ) -> ObjectId :
Original file line number Diff line number Diff line change 11from fastapi import status
22
3+
34class AppException (Exception ):
45 """Base application exception."""
6+
57 def __init__ (self , status_code : int , detail : str ):
68 self .status_code = status_code
79 self .detail = detail
810 super ().__init__ (detail )
911
12+
1013class UserAlreadyExistsError (AppException ):
1114 """Exception raised when a user tries to register with an email or username that already exists."""
12- def __init__ (self , detail : str = "User with this email or username already exists." ):
15+
16+ def __init__ (
17+ self , detail : str = "User with this email or username already exists."
18+ ):
1319 super ().__init__ (status_code = status .HTTP_409_CONFLICT , detail = detail )
1420
21+
1522class InternalServerError (AppException ):
1623 """Exception raised for internal server errors."""
24+
1725 def __init__ (self , detail : str = "An internal server error occurred." ):
18- super ().__init__ (status_code = status .HTTP_500_INTERNAL_SERVER_ERROR , detail = detail )
26+ super ().__init__ (
27+ status_code = status .HTTP_500_INTERNAL_SERVER_ERROR , detail = detail
28+ )
29+
30+
31+ class EmailNotVerifiedError (AppException ):
32+ """ " Exception raised when a user's email is not verified"""
33+
34+ def __init__ (self , detail : str = "User email is not verified" ):
35+ super ().__init__ (status_code = status .HTTP_403_FORBIDDEN , detail = detail )
You can’t perform that action at this time.
0 commit comments