Restart stream process if token expired

Addresses #2450
This commit is contained in:
Adrian Kumpf
2022-02-20 14:18:00 +01:00
parent f025a667e9
commit b209d348f8
2 changed files with 7 additions and 1 deletions
+5
View File
@@ -161,6 +161,11 @@ defmodule TeslaApi.Stream do
Logger.warn("Streaming API Client Error: #{error}")
{:close, state}
%{"value" => "Can't validate token" <> _} ->
Logger.warn("Streaming API: Tokens expired")
state.receiver.(:tokens_expired)
{:ok, state}
_ ->
raise "Client Error: #{inspect(msg)}"
end
+2 -1
View File
@@ -489,7 +489,8 @@ defmodule TeslaMate.Vehicles.Vehicle do
#### Rest
def handle_event(:info, {:stream, :too_many_disconnects}, _state, data) do
def handle_event(:info, {:stream, msg}, _state, data)
when msg in [:too_many_disconnects, :tokens_expired] do
Logger.info("Creating new connection … ", car_id: data.car.id)
ref = Process.monitor(data.stream_pid)