Skip to content

Commit

Permalink
Immediately stop stream when oauth config is invalid (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
parroty committed Aug 22, 2017
1 parent 694a58e commit 79626dc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/extwitter/api/streaming.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule ExTwitter.API.Streaming do
"""
@default_stream_timeout 60_000
@default_control_timeout 10_000
@http_unauthorized 401

require Logger

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 79626dc

Please sign in to comment.