From a5b34ccbff89bd137fff40d50948b24515d86889 Mon Sep 17 00:00:00 2001 From: cmaddox5 Date: Fri, 22 Nov 2024 09:28:01 -0500 Subject: [PATCH] Keep existing data if we can't decode source. --- lib/screens/last_trip/poller.ex | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/screens/last_trip/poller.ex b/lib/screens/last_trip/poller.ex index 55a6abe96..2cfa4a3b8 100644 --- a/lib/screens/last_trip/poller.ex +++ b/lib/screens/last_trip/poller.ex @@ -2,6 +2,7 @@ defmodule Screens.LastTrip.Poller do @moduledoc """ GenServer that polls predictions to calculate the last trip of the day """ + require Logger alias Screens.LastTrip.Cache alias Screens.LastTrip.Parser alias Screens.LastTrip.TripUpdates @@ -32,14 +33,20 @@ defmodule Screens.LastTrip.Poller do :ok = Cache.reset() %{state | next_reset: next_reset()} else - {:ok, - %{ - trip_updates: trip_updates, - vehicle_positions: vehicle_positions - }} = fetch_trip_updates_and_vehicle_positions() - - update_last_trips(trip_updates) - update_recent_departures(trip_updates, vehicle_positions) + case fetch_trip_updates_and_vehicle_positions() do + {:ok, + %{ + trip_updates: trip_updates, + vehicle_positions: vehicle_positions + }} -> + update_last_trips(trip_updates) + update_recent_departures(trip_updates, vehicle_positions) + + {:error, error} -> + Logger.warning( + "[last_trip_poller] failed while polling for new data: #{inspect(error)}" + ) + end state end @@ -57,6 +64,8 @@ defmodule Screens.LastTrip.Poller do trip_updates: trip_updates, vehicle_positions: vehicle_positions }} + else + {:error, error} -> {:error, error} end end