AOSSIE-Org / AOSSIE-Org/PictoPy

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

オープン
#1,179 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
283
フォーク
679
平均マージ
7日 2時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。