diff --git a/lib/screens/routes/route.ex b/lib/screens/routes/route.ex index c366bfa6b..93b2111a0 100644 --- a/lib/screens/routes/route.ex +++ b/lib/screens/routes/route.ex @@ -62,7 +62,7 @@ defmodule Screens.Routes.Route do end @doc "Fetches routes that serve the given stop." - @spec serving_stop(Stop.id()) :: {:ok, t()} | :error + @spec serving_stop(Stop.id()) :: {:ok, [t()]} | :error def serving_stop( stop_id, get_json_fn \\ &V3Api.get_json/2, diff --git a/lib/screens/v2/candidate_generator/dup/departures.ex b/lib/screens/v2/candidate_generator/dup/departures.ex index 0c8f8584c..1ae62cf89 100644 --- a/lib/screens/v2/candidate_generator/dup/departures.ex +++ b/lib/screens/v2/candidate_generator/dup/departures.ex @@ -638,7 +638,11 @@ defmodule Screens.V2.CandidateGenerator.Dup.Departures do ) do routes = stop_ids - |> Enum.flat_map(&fetch_routes_serving_stop_fn.(&1)) + |> Enum.map(&fetch_routes_serving_stop_fn.(&1)) + |> Enum.flat_map(fn + {:ok, routes} -> routes + :error -> [] + end) |> Enum.uniq() if route_ids == [] do diff --git a/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex b/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex index b7a53b2c3..354de3fde 100644 --- a/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex +++ b/lib/screens/v2/candidate_generator/widgets/elevator_closures.ex @@ -52,7 +52,7 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ElevatorClosures do |> MapSet.new() |> MapSet.put(home_parent_station_id) |> Enum.map(fn station_id -> - {station_id, station_id |> Route.serving_stop() |> routes_to_icons()} + {station_id, station_id |> routes_serving_stop() |> routes_to_icons()} end) |> Enum.into(%{}) end @@ -66,6 +66,13 @@ defmodule Screens.V2.CandidateGenerator.Widgets.ElevatorClosures do end) end + defp routes_serving_stop(stop_id) do + case Route.serving_stop(stop_id) do + {:ok, routes} -> routes + :error -> [] + end + end + defp routes_to_icons(routes) do routes |> Enum.map(fn diff --git a/test/screens/v2/candidate_generator/dup/departures_test.exs b/test/screens/v2/candidate_generator/dup/departures_test.exs index 8ed1f3832..a0ba24157 100644 --- a/test/screens/v2/candidate_generator/dup/departures_test.exs +++ b/test/screens/v2/candidate_generator/dup/departures_test.exs @@ -251,12 +251,12 @@ defmodule Screens.V2.CandidateGenerator.Dup.DeparturesTest do fetch_vehicles_fn = fn _, _ -> [struct(Vehicle)] end fetch_routes_serving_stop_fn = fn - "Boat" -> [%{id: "Ferry", type: :ferry}] - "place-A" -> [%{id: "Orange", type: :subway}, %{id: "Green", type: :light_rail}] - "bus-A" -> [%{id: "Bus A", type: :bus}] - "bus-B" -> [%{id: "Bus B", type: :bus}] - "place-overnight" -> [%{id: "Red", type: :subway}] - _ -> [%{id: "test", type: :test}] + "Boat" -> {:ok, [%{id: "Ferry", type: :ferry}]} + "place-A" -> {:ok, [%{id: "Orange", type: :subway}, %{id: "Green", type: :light_rail}]} + "bus-A" -> {:ok, [%{id: "Bus A", type: :bus}]} + "bus-B" -> {:ok, [%{id: "Bus B", type: :bus}]} + "place-overnight" -> {:ok, [%{id: "Red", type: :subway}]} + _ -> {:ok, [%{id: "test", type: :test}]} end %{