From 0fb3126fd22b23fdf3bc966e33ab8a8b654b42ca Mon Sep 17 00:00:00 2001 From: chihlasm Date: Thu, 26 Feb 2026 23:49:07 -0500 Subject: [PATCH] fix: add error logging and error type to AI builder 502 responses The generic "AI provider error" message made debugging impossible. Now logs the full exception traceback and includes the error class name in the 502 response detail. Co-Authored-By: Claude Opus 4.6 --- backend/app/api/endpoints/ai_builder.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/app/api/endpoints/ai_builder.py b/backend/app/api/endpoints/ai_builder.py index dcb0a966..c8771d16 100644 --- a/backend/app/api/endpoints/ai_builder.py +++ b/backend/app/api/endpoints/ai_builder.py @@ -195,6 +195,7 @@ async def scaffold( detail=f"AI returned invalid output: {e}", ) except Exception as e: + logger.exception("AI scaffold failed: %s: %s", type(e).__name__, e) await record_ai_usage( user_id=current_user.id, account_id=current_user.account_id, @@ -213,7 +214,7 @@ async def scaffold( await db.commit() raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, - detail="AI provider error. Please try again.", + detail=f"AI provider error ({type(e).__name__}). Please try again.", ) # Record successful usage @@ -314,6 +315,7 @@ async def branch_detail( detail=f"AI returned invalid output: {e}", ) except Exception as e: + logger.exception("AI branch_detail failed: %s: %s", type(e).__name__, e) await record_ai_usage( user_id=current_user.id, account_id=current_user.account_id, @@ -332,7 +334,7 @@ async def branch_detail( await db.commit() raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, - detail="AI provider error. Please try again.", + detail=f"AI provider error ({type(e).__name__}). Please try again.", ) # Record successful usage