Skip to content

Commit

Permalink
Handle error returns from lookup
Browse files Browse the repository at this point in the history
- see spec/fixtures/lookup-404.json for format
  • Loading branch information
leshill authored and sferik committed Dec 12, 2010
1 parent 9ddcbb1 commit 0553cdb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/faraday/raise_http_4xx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ def self.error_body(body)
elsif body['error']
": #{body['error']}"
elsif body['errors']
": #{body['errors'].to_a.first.chomp}"
first = body['errors'].to_a.first
if first.kind_of? Hash
": #{first['message'].chomp}"
else
": #{first.chomp}"
end
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/faraday/raise_http_4xx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@

end

context "when response status is 404 from lookup" do

before do
stub_get("users/lookup.json").
with(:query => {:screen_name => "not_on_twitter"}).
to_return(:status => 404, :body => fixture('lookup-404.json'))
end

it "should raise Twitter::NotFound" do
lambda do
@client.users('not_on_twitter')
end.should raise_error(Twitter::NotFound)
end

end

context "when response status is 406" do

before do
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/lookup-404.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "errors": [ { "code": 17, "message": "No user matches for specified terms" } ] }

0 comments on commit 0553cdb

Please sign in to comment.