From 7e765fe94a14e54d7fd4edf4bc297cefd6d550d9 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 14 Nov 2021 12:29:58 +0100 Subject: [PATCH] Properly handle stop not found --- main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 37313d0..b63b2f3 100644 --- a/main.py +++ b/main.py @@ -66,12 +66,12 @@ async def stop( if passages_res.status_code != 200: raise HTTPException( status_code=passages_res.status_code, - detail="HTTP error during call to remote API", + detail="HTTP error during call to remote passages API", ) if infos_res.status_code != 200: raise HTTPException( status_code=infos_res.status_code, - detail="HTTP error during call to remote API", + detail="HTTP error during call to remote info API", ) stop_ids = {monitored_stop_id} @@ -86,6 +86,9 @@ async def stop( passages[(ligne, destination)].append(passage.get("delaipassage")) stop_ids.add(destination) + if not passages: + raise HTTPException(status_code=404, detail="Stop not found") + stop_infos: Dict[int, Stop] = {} for info in infos_res.json().get("values"): stop_id = info.get("id")