-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: map headers only when not falsy #546
fix: map headers only when not falsy #546
Conversation
Thanks. But, in which case are headers nil? |
I've no clue, but run into it. :) |
@salzig please add a test case demonstrating the problem. Also, which adapter are you using? |
Closing as stale. There is no substantial evidence that this is a bug with Faraday; at least no other people are reporting it. |
I saw the same error when I tried doing the following: conn = Faraday.new(:url => 'http://httpbin.prg') do |faraday|
faraday.response :logger
end
conn.get('/get') # throws NoMethodError: undefined method `map' for nil:NilClass Specifying the adapter in the config block resolved the issue: conn = Faraday.new(:url => 'http://httpbin.prg') do |faraday|
faraday.response :logger
faraday.adapter Faraday.default_adapter
end Perhaps it was a mistake on my end to expect that to be able to only configure response logging there? |
When specifying a block to |
Yeah, that's what I figured out via trial and error, but maybe this is what caused the issue for @salzig as well? Would it make sense to have a safety belt, so that if the user passes in a block and doesn't configure the adapter, an exception is thrown? It would be more intuitive than having http calls fail inside the logging code because of the nil headers issue. |
That would make more sense. However, currently it's not possible to detect whether an adapter has been added to the middleware stack or not. That makes raising a helpful exception a harder problem. |
why is there a hard requirement to specify a adapter when using the block notation? |
@salzig situation is more or less like this:
Now, if you add to this the impossibility for us to detect the adapter at the moment, you'll see there's no safe way to "fix" a malformed stack provided by the user (e.g. missing the adapter). |
tried the
faraday.response :logger
, failed to me cause headers was nil.