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

Closed
wants to merge 6 commits into
from
View
@@ -7,7 +7,7 @@ Gem::Specification.new 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}
@@ -27,14 +27,17 @@ def initialize(app)
private
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)}"
end
def error_body(body)
if body.nil?
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']}"
end
end