🐛 Fix invalid line id returned by /stop/{stop_id}/nextPassages endpoint

This commit is contained in:
2023-05-09 23:25:30 +02:00
parent de82eb6c55
commit ef26509b87
2 changed files with 5 additions and 5 deletions

View File

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

View File

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