Skip to content
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

Closed
wants to merge 1 commit into from
Closed

fix: map headers only when not falsy #546

wants to merge 1 commit into from

Conversation

salzig
Copy link

@salzig salzig commented Nov 24, 2015

tried the faraday.response :logger, failed to me cause headers was nil.

@mislav
Copy link
Contributor

mislav commented Dec 31, 2015

Thanks. But, in which case are headers nil?

@salzig
Copy link
Author

salzig commented Jan 11, 2016

I've no clue, but run into it. :)

@sbleon
Copy link
Contributor

sbleon commented Apr 6, 2016

@salzig please add a test case demonstrating the problem.

Also, which adapter are you using?

@mislav
Copy link
Contributor

mislav commented Oct 17, 2016

Closing as stale. There is no substantial evidence that this is a bug with Faraday; at least no other people are reporting it.

@mislav mislav closed this Oct 17, 2016
@kilink
Copy link

kilink commented Apr 12, 2017

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?

@mislav
Copy link
Contributor

mislav commented Apr 12, 2017

When specifying a block to Faraday.new, you always need to explicitly specify an adapter, since none will be chosen for you.

@kilink
Copy link

kilink commented Apr 13, 2017

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.

@mislav
Copy link
Contributor

mislav commented Apr 13, 2017

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?

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.

@salzig
Copy link
Author

salzig commented Apr 18, 2017

why is there a hard requirement to specify a adapter when using the block notation?
(haven't used faraday for a while)

@iMacTia
Copy link
Member

iMacTia commented Apr 21, 2017

@salzig situation is more or less like this:

  • We need an adapter in the stack to perform the call.
  • There should be only one adapter in the stack (or the call will be performed multiple times)
  • The adapter must be always the last one in the stack (for the way the stack is built)

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).
However, this is being discussed in #121 and #685 if you want to keep an eye on it.
It will probably be an exclusive feature of Faraday v1.0

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

Successfully merging this pull request may close these issues.

5 participants