[32788f42] feat(list-generator): add detailed traceback logging for debugging 500 errors
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import Optional
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import traceback
|
||||||
from ..services.pdf_generator import generate_school_pdf
|
from ..services.pdf_generator import generate_school_pdf
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -26,6 +27,7 @@ async def generate_list(
|
|||||||
families_path = os.path.join(temp_dir, "families.csv")
|
families_path = os.path.join(temp_dir, "families.csv")
|
||||||
with open(families_path, "wb") as buffer:
|
with open(families_path, "wb") as buffer:
|
||||||
shutil.copyfileobj(families_file.file, buffer)
|
shutil.copyfileobj(families_file.file, buffer)
|
||||||
|
print(f"Generating PDF for: {institution}, Type: {list_type}")
|
||||||
pdf_path = generate_school_pdf(
|
pdf_path = generate_school_pdf(
|
||||||
institution=institution,
|
institution=institution,
|
||||||
date_info=date_info,
|
date_info=date_info,
|
||||||
@@ -35,7 +37,7 @@ async def generate_list(
|
|||||||
output_dir=temp_dir
|
output_dir=temp_dir
|
||||||
)
|
)
|
||||||
if not pdf_path or not os.path.exists(pdf_path):
|
if not pdf_path or not os.path.exists(pdf_path):
|
||||||
raise HTTPException(status_code=500, detail="PDF generation failed")
|
raise HTTPException(status_code=500, detail="PDF generation failed - file not created.")
|
||||||
with open(pdf_path, "rb") as f:
|
with open(pdf_path, "rb") as f:
|
||||||
pdf_bytes = f.read()
|
pdf_bytes = f.read()
|
||||||
final_output_path = os.path.join("/tmp", os.path.basename(pdf_path))
|
final_output_path = os.path.join("/tmp", os.path.basename(pdf_path))
|
||||||
@@ -43,4 +45,6 @@ async def generate_list(
|
|||||||
f.write(pdf_bytes)
|
f.write(pdf_bytes)
|
||||||
return FileResponse(path=final_output_path, filename=os.path.basename(pdf_path), media_type="application/pdf")
|
return FileResponse(path=final_output_path, filename=os.path.basename(pdf_path), media_type="application/pdf")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
print("ERROR IN GENERATE LIST:")
|
||||||
|
traceback.print_exc()
|
||||||
|
raise HTTPException(status_code=500, detail=f"Internal Server Error: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user