Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Response body for 400 errors was being incorrectly interpreted as nil #30

wants to merge 6 commits into from

3 participants


Error messages weren't displaying all the relevant information because the response body was not being parsed correctly. It seems this was because the JSON was escaped. Added explicit parsing of the response body and error is now more informative.


Hey wes, great pull request, I recently put in one for the same thing. I didn't see that faraday middleware also has a ::JSON available and think we should combine our commits. I used multi_json which isn't as good as using that available constant but I also added a test. Here is my pull request, let me know what you think:


Sounds like a good plan to me :)

@shayne shayne closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 14, 2012
  1. @wesnolte

    troubleshooting POST error

    wesnolte authored
  2. @wesnolte

    troubleshooting POST error

    wesnolte authored
  3. @wesnolte

    troubleshooting POST error

    wesnolte authored
  4. @wesnolte

    troubleshooting POST error

    wesnolte authored
  5. @wesnolte

    response body for 400 errors was not being parsed correctly because o…

    wesnolte authored
    …f escaped JSON leading to totes lame error messages. Added in explicit parsing of body.
Commits on Apr 22, 2012
  1. @wesnolte

    bumped multi_json to 1.2.0

    wesnolte authored
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 3 deletions.
  1. +1 −1  instagram.gemspec
  2. +5 −2 lib/faraday/raise_http_exception.rb
2  instagram.gemspec
@@ -7,7 +7,7 @@ do |s|
s.add_development_dependency('bluecloth', '~> 2.0.11')
s.add_runtime_dependency('faraday', '~> 0.7')
s.add_runtime_dependency('faraday_middleware', '~> 0.8')
- s.add_runtime_dependency('multi_json', '~> 1.0.3')
+ s.add_runtime_dependency('multi_json', '~> 1.2.0')
s.add_runtime_dependency('hashie', '>= 0.4.0')
s.authors = ["Shayne Sweeney"]
s.description = %q{A Ruby wrapper for the Instagram REST and Search APIs}
7 lib/faraday/raise_http_exception.rb
@@ -27,14 +27,17 @@ def initialize(app)
def error_message_400(response)
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
+ # response body is escaped JSON so it needs to be parsed
+ body = ::JSON.parse(response[:body])
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(body)}"
def error_body(body)
if body.nil?
elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
- ": #{body['meta']['error_message']}"
+ ": #{body['meta']['error_type']} - #{body['meta']['error_message']}"
Something went wrong with that request. Please try again.