Skip to content

Commit 3331dd7

Browse files
committed
fix: Prevent fallback to 400 errors when linting fails
🔧 Core Issue Resolution: - Changed exception handling in linting stage to return 200 OK instead of continuing processing - When linting service fails (e.g., PDF generation issues), return JSON error response with 200 status - Prevents fallback to normal template processing that results in 400 Bad Request errors 📋 Changes: - Modified exception handler to return JSONResponse with 200 status on linting failures - Added detailed error logging with traceback for debugging - Ensures file cleanup on linting service errors - Provides clear error message indicating likely template validation issues ✅ Expected Behavior: - Template validation errors: 200 OK with PDF error report - Linting service errors: 200 OK with JSON error message - No more 400 Bad Request responses for template validation issues
1 parent 6f8c3f2 commit 3331dd7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

main.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,26 @@ async def process_document_template(
938938

939939
except Exception as e:
940940
logger.error(f"Template linting failed: {str(e)}")
941-
# Don't block processing on linting errors - just log and continue
942-
logger.warning("Continuing with template processing despite linting failure")
941+
logger.error(f"Linting error traceback: {traceback.format_exc()}")
942+
943+
# Clean up uploaded file
944+
if os.path.exists(file_path):
945+
os.remove(file_path)
946+
947+
# For linting failures, return JSON error response as fallback
948+
return JSONResponse(
949+
status_code=200,
950+
content={
951+
"status": "linting_service_error",
952+
"message": f"Template linting service failed: {str(e)}",
953+
"error_type": "linting_service_error",
954+
"details": {
955+
"filename": file.filename,
956+
"linting_error": str(e),
957+
"suggestion": "The template likely has validation errors. Check template syntax and try again."
958+
}
959+
}
960+
)
943961

944962
# Stage 2: Template Loading and Image Processing
945963
try:

0 commit comments

Comments
 (0)