fix:chek-email

This commit is contained in:
muhamad fais aizat 2025-05-16 17:41:06 +07:00
parent c88f5c6660
commit fa50712c31
1 changed files with 7 additions and 4 deletions

View File

@ -107,9 +107,8 @@ 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:
with conn.begin(): # transaksi otomatis query = select(users).where(users.c.email == email)
query = select(users).where(users.c.email == email) result = conn.execute(query).fetchone()
result = conn.execute(query).fetchone()
if result: if result:
return {"message": "true"} return {"message": "true"}
@ -117,7 +116,11 @@ 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:
try:
conn.rollback() # Jika sebelumnya ada transaksi yang belum selesai
except:
pass
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:
raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}") raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}")