AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: /images/toggle-favourite returns 500 instead of 404 for unknown image_id

未关闭
#1,179 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
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 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。