fix:chek-email

This commit is contained in:
muhamad fais aizat 2025-05-16 17:04:43 +07:00
parent 4eb0868e44
commit 33ebfa8318
1 changed files with 5 additions and 6 deletions

View File

@ -87,8 +87,9 @@ class CekEmail(BaseModel):
@auth_router.get("/check-email") @auth_router.get("/check-email")
async def check_email(email: str = Query(..., description="Email yang akan dicek")): async def check_email(email: str = Query(..., description="Email yang akan dicek")):
try: try:
query = select(users).where(users.c.email == email) with conn.begin(): # transaksi otomatis
result = conn.execute(query).fetchone() query = select(users).where(users.c.email == email)
result = conn.execute(query).fetchone()
if result: if result:
return {"message": "true"} return {"message": "true"}
@ -96,9 +97,7 @@ async def check_email(email: str = Query(..., description="Email yang akan dicek
raise HTTPException(status_code=400, detail="false") raise HTTPException(status_code=400, detail="false")
except SQLAlchemyError as e: except SQLAlchemyError as e:
# Error dari SQLAlchemy (query, koneksi, dsb)
raise HTTPException(status_code=500, detail=f"Database error: {str(e)}") raise HTTPException(status_code=500, detail=f"Database error: {str(e)}")
except Exception as e: except Exception as e:
# Error lain yang tak terduga
raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}") raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}")