From d29e9ee89a5dd335a3f583774edff3b8b1b03247 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 4 Mar 2025 18:38:31 -0600 Subject: [PATCH] Improve error reporting Log an error when images/dates do not match. Also, show the response body in the error modal on the client side. --- index.html | 10 ++++++---- receipts.py | 8 ++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 93df6df..babb158 100644 --- a/index.html +++ b/index.html @@ -102,10 +102,12 @@ "Successfully uploaded receipts" ); } else { - showDialog( - "Upload Failure", - `Failed to upload receipts: ${r.statusText}`, - ); + r.text().then((msg) => { + showDialog( + "Upload Failure", + `Failed to upload receipts: ${r.statusText}\n${msg}`, + ); + }); } form.reset(); }) diff --git a/receipts.py b/receipts.py index ff8fd62..72a83eb 100644 --- a/receipts.py +++ b/receipts.py @@ -92,10 +92,14 @@ async def upload_receipts( # notes: Annotated[list[str], fastapi.Form(alias='notes[]')], ): if len(dates) != len(images): + msg = ( + f'Number of uploaded images ({len(images)})' + f' does not match number of date fields ({len(dates)})' + ) + log.warning('%s', msg) raise fastapi.HTTPException( status_code=fastapi.status.HTTP_400_BAD_REQUEST, - detail='Number of uploaded images does not match ' - 'number of date fields', + detail=msg, ) failed = False async with Paperless() as paperless: