🐛 Fix invalid line id returned by /stop/{stop_id}/nextPassages endpoint
This commit is contained in:
@@ -38,7 +38,6 @@ from .idfm_types import (
|
|||||||
from .ratp_types import Picto as RatpPicto
|
from .ratp_types import Picto as RatpPicto
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ class IdfmInterface:
|
|||||||
)
|
)
|
||||||
|
|
||||||
OPERATOR_RE = re_compile(r"[^:]+:Operator::([^:]+):")
|
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:
|
def __init__(self, api_key: str, database: Database) -> None:
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
|
@@ -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.
|
# re.match will return None if the given journey.LineRef.value is not valid.
|
||||||
try:
|
try:
|
||||||
line_id = IdfmInterface.LINE_RE.match(journey.LineRef.value).group(1)
|
line_id_match = IdfmInterface.LINE_RE.match(journey.LineRef.value)
|
||||||
except AttributeError as exc:
|
line_id = int(line_id_match.group(1)) # type: ignore
|
||||||
|
except (AttributeError, TypeError, ValueError) as err:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404, detail=f'Line "{journey.LineRef.value}" not found'
|
status_code=404, detail=f'Line "{journey.LineRef.value}" not found'
|
||||||
) from exc
|
) from err
|
||||||
|
|
||||||
call = journey.MonitoredCall
|
call = journey.MonitoredCall
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user