Dwolla / dwolla-v2-ruby

Official Ruby Wrapper for Dwolla's API v2
https://developers.dwolla.com/
MIT License
22 stars 17 forks source link

Faraday Response Middleware - response details missing #14

Closed namelessnotion closed 8 years ago

namelessnotion commented 8 years ago

When using faraday response middleware (for say debug logging) in the on_complete the response details (status, headers, body etc.) are missing.

For example the middleware below (the response logger that ships with faraday gives me the same results)

def call(env)
  info "#{env.method} #{env.url.to_s}"
  debug('request') { dump_headers env.request_headers }
  debug('request') { dump_body(env[:body]) } if env[:body] && log_body?(:request)
  @app.call(env).on_complete do |response_env|
    info('Status') { response_env.status.to_s }
    debug('response') { dump_headers response_env.response_headers }
    debug('response') { dump_body response_env[:body] } if env[:body] && log_body?(:response)
  end
end

When a Dwolla request is ran response_env.response_headers is nil and the response_env.body is actually the request body.

I've used this type of response middleware logging before (with other faraday setups) without issue and it's very helpful for debugging requests.