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.
python
Dustin 2025-03-04 18:38:31 -06:00
parent c6f570100b
commit d29e9ee89a
2 changed files with 12 additions and 6 deletions

View File

@ -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();
})

View File

@ -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: