Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…brought back by the server.
  • Loading branch information...
commit 9af8b9e8a5f4f194faffc9cdd7245dec9ad7e906 1 parent f8af597
@eerwitt eerwitt authored
View
5 lib/faraday/raise_http_exception.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?
View
14 spec/faraday/response_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.