2525from app .services .analysis_orchestrator import AnalysisOrchestrator
2626from app .core .exceptions import NotFoundException , NotAuthorizedException
2727from app .services .interfaces .embedding_generator import EmbeddingGeneratorInterface
28+ from app .core .exceptions import MonthlyLimitExceededError
2829
2930router = APIRouter (prefix = "/claims" , tags = ["claims" ])
3031logger = logging .getLogger (__name__ )
@@ -45,8 +46,12 @@ async def create_claim(
4546 language = data .language ,
4647 batch_user_id = data .batch_user_id ,
4748 batch_post_id = data .batch_post_id ,
49+ auth0_id = current_user .auth0_id ,
4850 )
4951 return ClaimRead .model_validate (claim )
52+ except MonthlyLimitExceededError :
53+ # We don't have 'e.limit' anymore, so we just say "Limit reached"
54+ raise HTTPException (status_code = 429 , detail = "You have reached your monthly claim limit." )
5055 except Exception as e :
5156 raise HTTPException (
5257 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR , detail = f"Failed to create claim: { str (e )} "
@@ -65,12 +70,19 @@ async def create_claims_batch(
6570 raise HTTPException (status_code = 400 , detail = "Maximum of 100 claims allowed." )
6671
6772 try :
68- created_claims = await claim_service .create_claims_batch (claims , current_user .id )
73+ created_claims = await claim_service .create_claims_batch (
74+ claims ,
75+ current_user .id ,
76+ auth0_id = current_user .auth0_id ,
77+ )
6978 claim_ids = [str (claim .id ) for claim in created_claims ]
7079 background_tasks .add_task (
7180 claim_service .process_claims_batch_async , created_claims , current_user .id , analysis_orchestrator
7281 )
7382 return {"message" : f"Processing { len (created_claims )} claims in the background." , "claim_ids" : claim_ids }
83+ except MonthlyLimitExceededError :
84+ # We don't have 'e.limit' anymore, so we just say "Limit reached"
85+ raise HTTPException (status_code = 429 , detail = "You have reached your monthly claim limit." )
7486 except Exception as e :
7587 raise HTTPException (
7688 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR , detail = f"Failed to queue batch: { str (e )} "
0 commit comments