Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/audioformation/server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ async def ingest_files(
shutil.copyfileobj(file.file, buffer)
except Exception as e:
shutil.rmtree(tmp_dir, ignore_errors=True)
raise HTTPException(status_code=500, detail=f"Upload failed: {e}")
logger.exception(f"Ingest upload failed: {e}")
raise HTTPException(status_code=500, detail="Upload failed")
Comment on lines +188 to +189
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation catches all exceptions and returns a 500 Internal Server Error. However, sanitize_filename raises a ValueError if the input is invalid (e.g., empty after sanitization), which is a client-side error that should return a 400 Bad Request. Returning a 500 error for client-side issues can mislead users and trigger unnecessary server-side alerts.

Additionally, when using logger.exception(), the exception details (message and traceback) are automatically captured and appended to the log output. Including {e} in the message string is redundant and leads to cluttered logs where the error message appears twice.

        if isinstance(e, ValueError):
            raise HTTPException(status_code=400, detail=str(e))
        logger.exception("Ingest upload failed")
        raise HTTPException(status_code=500, detail="Upload failed")


background_tasks.add_task(
_run_with_status,
Expand Down
Loading