lib/faraday/response/raise_http_error.rb in lelylan-rb-0.0.3 vs lib/faraday/response/raise_http_error.rb in lelylan-rb-0.0.4

- old
+ new

@@ -1,7 +1,7 @@ require 'faraday' -require 'multi_json' +require 'hashie' module Faraday class Response::RaiseHttpError < Response::Middleware def on_complete(response) case response[:status].to_i @@ -27,9 +27,16 @@ raise Lelylan::ServiceUnavailable, error_message(response) end end def error_message(response) - response[:body] + body = response[:body] || '' + + begin + body = Hashie::Mash.new(JSON.parse(response[:body])) + rescue + end + + body.is_a?(::Hashie::Mash) ? body.error.description : body end end end