Permalink
Browse files

changes for faraday exception raising to return the body of messages …

…brought back by the server.
  • Loading branch information...
1 parent f8af597 commit 9af8b9e8a5f4f194faffc9cdd7245dec9ad7e906 @eerwitt eerwitt committed Apr 19, 2012
Showing with 19 additions and 0 deletions.
  1. +5 −0 lib/faraday/raise_http_exception.rb
  2. +14 −0 spec/faraday/response_spec.rb
@@ -31,6 +31,11 @@ def error_message_400(response)
end
def error_body(body)
+ # body gets passed as a string, not sure if it is passed as something else from other spots. Checking specs.
+ if not body.nil? and not body.empty? and body.kind_of?(String)
+ body = MultiJson.decode(body)
+ end
+
if body.nil?
nil
elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
@@ -23,6 +23,20 @@
@client.user_media_feed()
end.should raise_error(exception)
end
+
+ end
+ end
+
+ context "when a 400 is raised" do
+ before do
+ stub_get('users/self/feed.json').
+ to_return(:body => '{"meta":{"error_message": "Bad words are bad."}}', :status => 400)
+ end
+
+ it "should return the body error message" do
+ expect do
+ @client.user_media_feed()
+ end.should raise_error(Instagram::BadRequest, /Bad words are bad./)
end
end
end

0 comments on commit 9af8b9e

Please sign in to comment.