Return 404 not found for invalid trip IDs

Closes: #103
This commit is contained in:
Edward Betts 2024-01-12 14:08:36 +00:00
parent 2744f67987
commit a9c9c719a4

View file

@ -237,10 +237,15 @@ def trip_list() -> str:
@app.route("/trip/<start>") @app.route("/trip/<start>")
def trip_page(start: str) -> str: def trip_page(start: str) -> str:
"""Individual trip page."""
trip_list = build_trip_list() trip_list = build_trip_list()
today = date.today() today = date.today()
trip = next((trip for trip in trip_list if trip.start.isoformat() == start), None) trip = next((trip for trip in trip_list if trip.start.isoformat() == start), None)
if not trip:
flask.abort(404)
return flask.render_template( return flask.render_template(
"trip_page.html", "trip_page.html",
trip=trip, trip=trip,