-
-
Notifications
You must be signed in to change notification settings - Fork 602
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
What happened?
POST /images/toggle-favourite with a fake image_id returns 500 Internal Server Error but should return 404 Not Found
Steps to Reproduce
Start the backend service: uvicorn main:app --host 127.0.0.1 --port 52123
In a new terminal, run:
curl -i -X POST http://127.0.0.1:52123/images/toggle-favourite
-H "Content-Type: application/json"
-d "{"image_id":"non-existent-id-123"}"
Observe the response.
Current Behaviour:
The endpoint returns:
HTTP/1.1 500 Internal Server Error
{"detail":"Internal server error: 404: Image not found or failed to toggle"}
Expected Behaviour
The endpoint should return:
HTTP/1.1 404 Not Found
{"detail":"Image not found or failed to toggle"}
Root Cause:
In images.py, the route correctly raises a 404 error when the image isn’t found.
But later in the same function, there’s a broad except Exception block that catches everything — including that 404. When that happens, it turns the 404 into a 500 Internal Server Error.
So instead of returning the correct “not found” response, the API ends up sending a 500, which makes it look like the server crashed.
Record
- I agree to follow this project's Code of Conduct