Permalink
Browse files

Handle error returns from lookup

- see spec/fixtures/lookup-404.json for format
  • Loading branch information...
1 parent 9ddcbb1 commit 0553cdbe262f006fae149309ce51a03985ed8fd2 @leshill leshill committed with Dec 12, 2010
Showing with 23 additions and 1 deletion.
  1. +6 −1 lib/faraday/raise_http_4xx.rb
  2. +16 −0 spec/faraday/raise_http_4xx_spec.rb
  3. +1 −0 spec/fixtures/lookup-404.json
@@ -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
@@ -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
@@ -0,0 +1 @@
+{ "errors": [ { "code": 17, "message": "No user matches for specified terms" } ] }

0 comments on commit 0553cdb

Please sign in to comment.