From 79626dcfc2a5c5ab02d14b06f4631c8a9f1b572c Mon Sep 17 00:00:00 2001 From: parroty Date: Tue, 22 Aug 2017 22:45:49 +0900 Subject: [PATCH] Immediately stop stream when oauth config is invalid (#81) --- lib/extwitter/api/streaming.ex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/extwitter/api/streaming.ex b/lib/extwitter/api/streaming.ex index 7c48bb7..7987009 100644 --- a/lib/extwitter/api/streaming.ex +++ b/lib/extwitter/api/streaming.ex @@ -8,6 +8,7 @@ defmodule ExTwitter.API.Streaming do """ @default_stream_timeout 60_000 @default_control_timeout 10_000 + @http_unauthorized 401 require Logger @@ -108,6 +109,10 @@ defmodule ExTwitter.API.Streaming do Logger.warn "Connection closed remotely, restarting stream" receive_next_tweet(nil, req, timeout) + {:error, message} -> + Logger.error "Error returned, stopping stream (#{message})." + {:halt, {req, pid}} + _ -> receive_next_tweet(pid, req, timeout) @@ -154,6 +159,9 @@ defmodule ExTwitter.API.Streaming do {:http, {_request_id, {:error, reason}}} -> send processor, {:error, reason} + {:http, {_request_id, {{_http, @http_unauthorized, msg}, _headers, _body}}} -> + send processor, {:error, msg} + {:cancel, requester} -> :httpc.cancel_request(request_id) send requester, :ok