lib/search_spring/errors.rb in search_spring-0.2.1 vs lib/search_spring/errors.rb in search_spring-0.2.5

- old
+ new

@@ -6,10 +6,22 @@ class InternalServerError < SearchSpringError; end class NotAuthorized < SearchSpringError; end class AuthenticationError < SearchSpringError; end class RequestError < Faraday::Response::Middleware + def call(env) + @request_data = { + url: env.url.to_s, + method: env.method, + header: env[:request_headers], + body: env.body + } + @app.call(env).on_complete do |environment| + on_complete(environment) + end + end + def on_complete(env) # Ignore any non-error response codes return if (status = env[:status]) < 400 case status when 404 @@ -25,10 +37,13 @@ raise Errors::InternalServerError, response_values(env) # Treat any other errors as 500 end end def response_values(env) - { status: env.status, headers: env.response_headers, body: env.body } + { status: env.status, + headers: env.response_headers, + body: env.body, + request: (@request_data || {}) } end end end end