44
55import jwt
66from asyncpg import UniqueViolationError
7- from fastapi import HTTPException , status
87from pydantic import EmailStr , Field , HttpUrl , SecretStr , field_validator
98from sqlalchemy import exc
109
1110from futuramaapi .core import feature_flags , settings
1211from futuramaapi .helpers .pydantic import BaseModel
1312from futuramaapi .repositories .models import UserModel
14- from futuramaapi .routers .services import BaseSessionService
13+ from futuramaapi .routers .services import BaseSessionService , ConflictError , RegistrationDisabledError
1514
1615from .get_user_me import GetUserMeResponse
1716
@@ -119,10 +118,7 @@ def _get_user(self) -> UserModel:
119118
120119 async def process (self , * args , ** kwargs ) -> CreateUserResponse :
121120 if not feature_flags .user_signup :
122- raise HTTPException (
123- status_code = status .HTTP_403_FORBIDDEN ,
124- detail = "User registration is currently disabled" ,
125- )
121+ raise RegistrationDisabledError ()
126122
127123 user : UserModel = self ._get_user ()
128124 self .session .add (user )
@@ -131,10 +127,7 @@ async def process(self, *args, **kwargs) -> CreateUserResponse:
131127 await self .session .commit ()
132128 except exc .IntegrityError as err :
133129 if err .orig .sqlstate == UniqueViolationError .sqlstate :
134- raise HTTPException (
135- status_code = status .HTTP_422_UNPROCESSABLE_CONTENT ,
136- detail = "User already exists." ,
137- ) from None
130+ raise ConflictError ("User already exists." ) from None
138131 raise
139132
140133 await self ._send_confirmation_email (user )
0 commit comments