Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the streaming API raise exceptions for status codes. #558

Merged
merged 1 commit into from
Apr 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/twitter/streaming/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def <<(data)
@parser << data
end

def on_headers_complete(headers)
# TODO: handle response codes
p(:status_code => @parser.status_code, :header => headers) unless @parser.status_code == 200
def on_headers_complete(_headers)
error = Twitter::Error.errors[@parser.status_code]
fail error.new if error
end

def on_body(data)
Expand Down
21 changes: 21 additions & 0 deletions spec/twitter/streaming/response_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'helper'

describe Twitter::Streaming::Response do
subject { Twitter::Streaming::Response.new }

describe '#on_headers_complete' do
it 'should not error if status code is 200' do
expect do
subject << "HTTP/1.1 200 OK\r\nSome-Header: Woo\r\n\r\n"
end.to_not raise_error
end

Twitter::Error.errors.each do |code, klass|
it "should raise an exception of type #{klass} for status code #{code}" do
expect do
subject << "HTTP/1.1 #{code} NOK\r\nSome-Header: Woo\r\n\r\n"
end.to raise_error(klass)
end
end
end
end