Skip to content

Commit 51d44fb

Browse files
committed
fix(vehicle): handle :too_many_request in list_vehicles! and fetch_strict
Testing the previous commit against a live EXCEEDED_LIMIT ban surfaced two spots where {:error, :too_many_request, retry_after} was never handled, even though this shape already existed for plain HTTP 429s: - Vehicles.list_vehicles!/0 (called once at application boot) had no matching case clause, so a rate-limited "list vehicles" call crashed the whole application at startup - and with restart: always, that's a boot-crash-loop that keeps calling the rate-limited endpoint. - Vehicle.fetch_strict/2 (used by the manual "suspend logging" action) had the same gap, which would crash that vehicle's process if triggered while rate-limited. Both now fall back gracefully instead of crashing: list_vehicles! uses its existing fallback_vehicles() (cached cars from the DB), and fetch_strict returns {:error, {:too_many_request, retry_after}} in the same {:error, reason} shape its one caller already expects.
1 parent 45b82f7 commit 51d44fb

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/teslamate/vehicles.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ defmodule TeslaMate.Vehicles do
8383
{:error, :not_signed_in} ->
8484
fallback_vehicles()
8585

86+
{:error, :too_many_request, retry_after} ->
87+
Logger.warning("Could not get vehicles: rate limited, retry after #{retry_after}s")
88+
fallback_vehicles()
89+
8690
{:error, reason} ->
8791
Logger.warning("Could not get vehicles: #{inspect(reason)}")
8892
fallback_vehicles()

lib/teslamate/vehicles/vehicle.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,9 @@ defmodule TeslaMate.Vehicles.Vehicle do
15581558
{:ok, %V{}} ->
15591559
{:error, :gateway_error}
15601560

1561+
{:error, :too_many_request, retry_after} ->
1562+
{:error, {:too_many_request, retry_after}}
1563+
15611564
{:error, reason} ->
15621565
{:error, reason}
15631566
end

0 commit comments

Comments
 (0)