-
Notifications
You must be signed in to change notification settings - Fork 981
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
Faraday::ParsingError.response_status doesn't return expected value when stubbing response #1509
Comments
Thank you for opening this @brendo, it does look like a bug indeed! What's going on?The stacktrace above was not really helpful, but I managed to reproduce this locally and get a more interesting one: res = Faraday::Response.new(status: 502)
res[:status]
# => warning: Faraday::Response#[] at
# /.rvm/gems/ruby-3.2.2/gems/faraday-2.7.6/lib/faraday/response.rb:30 forwarding to private method NilClass#[]
# /.rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/forwardable.rb:238:in `[]': undefined method `[]' for nil:NilClass (NoMethodError) And that's becasue Now, I suspect this was originally OK for The confusion arise from the fact that I'll get those fixed 👍 |
Thank you so much! We were going a bit crazy and after logging this issue also ran into similar issues with
|
Absolutely, you should use those helpers because they abstract the underlying structure which again can be either a hash or a
will only work if |
@iMacTia why is error.response sometimes a hash? Why not always return a proper |
It's mostly due to historical reasons, hence why the helpers have been put in place to mitigate the issue, but some people's code might rely on using |
Basic Info
Issue description
I'll start off by saying I'm not sure this is an error in production, but we've encountered it when attempting to mock/test our application's handling of odd responses. In particular, we're currently testing that when a parsing error occurs that the HTTP status code will be what the server returned.
Steps to reproduce
I slightly modified the existing test in
json_spec
to demonstrate the "bug":This test will fail:
It appears that
response_status
will delegate toresponse[:status]
and this will attempt to find the status using the headers of the stubbed response. In this test, the headers arenil
, so it blows up.I'm curious, should it be
response.status
instead, or should we stubbing our responses as:The text was updated successfully, but these errors were encountered: