Skip to content

Commit

Permalink
call on_error on parser errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stve committed Jun 8, 2011
1 parent 2e878d1 commit 6685098
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tweetstream/client.rb
Expand Up @@ -230,11 +230,12 @@ def start(path, query_parameters = {}, &block) #:nodoc:
begin
raw_hash = @parser.decode(item)
rescue MultiJson::DecodeError
error_proc.call("MultiJson::DecodeError occured in stream: #{item}") if error_proc.is_a?(Proc)
next
end

unless raw_hash.is_a?(::Hash)
error_proc.call("Unexpected JSON object in stream: #{item}")
error_proc.call("Unexpected JSON object in stream: #{item}") if error_proc.is_a?(Proc)
next
end

Expand Down
7 changes: 7 additions & 0 deletions spec/tweetstream/client_spec.rb
Expand Up @@ -133,6 +133,13 @@
message.should == 'Unexpected JSON object in stream: ["favorited"]'
end.track('abc')
end

it 'should call on_error if a json parse error occurs' do
@stream.should_receive(:each_item).and_yield("{'a_key':}")
@client.on_error do |message|
message.should == "MultiJson::DecodeError occured in stream: {'a_key':}"
end.track('abc')
end
end

describe '#on_error' do
Expand Down

0 comments on commit 6685098

Please sign in to comment.