Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

NoMethodError: undefined method '[]=' for nil:NilClass #51

Open
vladimir-konnov opened this issue Jun 13, 2017 · 1 comment
Open

NoMethodError: undefined method '[]=' for nil:NilClass #51

vladimir-konnov opened this issue Jun 13, 2017 · 1 comment

Comments

@vladimir-konnov
Copy link

Hi!
I'm using version 0.16.0 and I'm using config.include_headers_in_response = true configuration option. Here's the stacktrace:

…-ruby-4b4dcabc0da4/lib/faraday/response/add_headers.rb:    4:in `on_complete'
…gems/2.4.0/gems/faraday-0.10.1/lib/faraday/response.rb:    9:in `block in call'
…gems/2.4.0/gems/faraday-0.10.1/lib/faraday/response.rb:   61:in `on_complete'
…gems/2.4.0/gems/faraday-0.10.1/lib/faraday/response.rb:    8:in `call'
…gems/2.4.0/gems/faraday-0.10.1/lib/faraday/response.rb:    8:in `call'
…gems/faraday-0.10.1/lib/faraday/request/url_encoded.rb:   15:in `call'
…/2.4.0/gems/faraday-0.10.1/lib/faraday/rack_builder.rb:  139:in `build_response'
…ms/2.4.0/gems/faraday-0.10.1/lib/faraday/connection.rb:  377:in `run_request'
…ms/2.4.0/gems/faraday-0.10.1/lib/faraday/connection.rb:  140:in `get'
…ntact-api-ruby-4b4dcabc0da4/lib/fullcontact/request.rb:   17:in `request'
…ntact-api-ruby-4b4dcabc0da4/lib/fullcontact/request.rb:    6:in `get'
…api-ruby-4b4dcabc0da4/lib/fullcontact/client/person.rb:   15:in `person'
…s/fullcontact-api-ruby-4b4dcabc0da4/lib/fullcontact.rb:   23:in `method_missing'
…services/contacts/full_contact/full_contact_service.rb:   32:in `person'
...

So it seems that when FullContact returns error (NotFound for example), then in the on_complete callback env.body is nil.

@vladimir-konnov
Copy link
Author

Which version of fullcontact gem will include the fix for this bug? I can propose the following straightforward solution:

module Faraday
  class Response::AddHeaders < Response::Middleware
    def on_complete(env)
      (env.body ||= {})[:http_headers] = env.response_headers
      env.body
    end
  end
end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant