🐛 Validate pin existence before adding image and improve error handling

master
parent 1b2df687c5
commit 0b6973c939

@ -131,6 +131,10 @@ async def add_image(
else:
os.remove(temp_path)
if not pin_id == 'null':
if(pins_collection.find_one({"_id": ObjectId(pin_id)}) is None):
raise HTTPException(status_code=404, detail="Pin not found")
# Créer l'entrée en base de données
image_doc = {
"pin_id": ObjectId(pin_id) if pin_id != 'null' else None,
@ -148,8 +152,8 @@ async def add_image(
return {"id": str(image_id)}
except Exception as e:
# Nettoyer en cas d'erreur
except (OSError, IOError) as e:
# Nettoyer en cas d'erreur liée au système de fichiers
if os.path.exists(temp_path):
os.remove(temp_path)
raise HTTPException(status_code=500, detail=str(e))
@ -213,7 +217,7 @@ async def update_caption(
)
async def get_caption(id: str, current_user: User = Depends(get_current_user)):
image = check_image_permissions(id, current_user)
return ImageCaptionDTO(caption=image.get("caption", ""))
return ImageCaptionDTO(caption=image.get("caption", " "))
@images_router.get(
path="/{id}/metadata",

Loading…
Cancel
Save