AOSSIE-Org / AOSSIE-Org/PictoPy

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

Abierto
#1,179 4 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
283
Forks
679
Merge medio
7 d 2 h
PR fusionados (30 d)
3

Descripción

### 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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.