AOSSIE-Org / AOSSIE-Org/PictoPy
BUG: /images/toggle-favourite returns 500 instead of 404 for unknown image_id
- 主要語言
- Python
- 星號
- 283
- 分支
- 679
- 平均合併
- 7 天 2 小時
- 30 天內合併 PR
- 3
描述
### Is there an existing issue for this?
- [x] 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
- [x] I agree to follow this project's Code of Conduct
貢獻指南
評估
這個 Issue 還沒有評估資料。