From ef26509b87cbad9169c625639c6cb07b68124c39 Mon Sep 17 00:00:00 2001 From: Adrien Date: Tue, 9 May 2023 23:25:30 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20invalid=20line=20id=20retu?= =?UTF-8?q?rned=20by=20/stop/{stop=5Fid}/nextPassages=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/backend/idfm_interface/idfm_interface.py | 3 +-- backend/main.py | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/backend/idfm_interface/idfm_interface.py b/backend/backend/idfm_interface/idfm_interface.py index 99ea17e..82b4316 100644 --- a/backend/backend/idfm_interface/idfm_interface.py +++ b/backend/backend/idfm_interface/idfm_interface.py @@ -38,7 +38,6 @@ from .idfm_types import ( from .ratp_types import Picto as RatpPicto - logger = getLogger(__name__) @@ -60,7 +59,7 @@ class IdfmInterface: ) OPERATOR_RE = re_compile(r"[^:]+:Operator::([^:]+):") - LINE_RE = re_compile(r"[^:]+:Line::([^:]+):") + LINE_RE = re_compile(r"[^:]+:Line::C([^:]+):") def __init__(self, api_key: str, database: Database) -> None: self._api_key = api_key diff --git a/backend/main.py b/backend/main.py index e5a1f08..80d615b 100755 --- a/backend/main.py +++ b/backend/main.py @@ -199,11 +199,12 @@ async def get_next_passages(stop_id: int) -> NextPassagesSchema | None: # re.match will return None if the given journey.LineRef.value is not valid. try: - line_id = IdfmInterface.LINE_RE.match(journey.LineRef.value).group(1) - except AttributeError as exc: + line_id_match = IdfmInterface.LINE_RE.match(journey.LineRef.value) + line_id = int(line_id_match.group(1)) # type: ignore + except (AttributeError, TypeError, ValueError) as err: raise HTTPException( status_code=404, detail=f'Line "{journey.LineRef.value}" not found' - ) from exc + ) from err call = journey.MonitoredCall