lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.71k stars 972 forks source link

NoMethodError: undefined method `method=' for #<Faraday::RequestOptions (empty) #1496

Closed uday708 closed 1 year ago

uday708 commented 1 year ago

Basic Info

Issue description

I am facing issue

NoMethodError: undefined method `method=' for #<Faraday::RequestOptions (empty)>                                                                                                                                                                
Did you mean?  method                                                                                                                                                                                                                                                            

Trail

2.6.0/gems/faraday-1.10.2/lib/faraday/options.rb:23:in `update'                                                                                                                                                                                        
/jruby/2.6.0/gems/faraday-1.10.2/lib/faraday/options.rb:9:in `from'                                                                                                                                                                                           
/jruby/2.6.0/gems/faraday-1.10.2/lib/faraday/options.rb:26:in `block in update'                                                                                                                                                                               
org/jruby/RubyHash.java:1519:in `each'                                                                                                                                                                                                                                           
/jruby/2.6.0/gems/faraday-1.10.2/lib/faraday/options.rb:23:in `update'                                                                                                                                                                                        
/jruby/2.6.0/gems/faraday-1.10.2/lib/faraday/options.rb:9:in `from'                                                                                                                                                                                           
jruby/2.6.0/gems/faraday-1.10.2/lib/faraday/options/env.rb:76:in `from'
iMacTia commented 1 year ago

Hi @uday708, sorry you're having this issue. Unfortunately we don't have any expertise with JRuby, but let me see if I can help. The error itself and the stack trace are not very helpful, would you be able to share the portion of your code that is causing this issue? Are you initialising a new faraday connection, or running a request?

uday708 commented 1 year ago

Hi @iMacTia It is coming when I am triggering Faraday::Env.from(e.response) this code e.response is:

{
  :status => 404,
  :headers => {},
  :body => "{}",
  :request => {
    :method => :post,
    :url_path => "/xyz",
    :params => nil,
    :headers => {
      "User-Agent" => "xyz",
      "Content-Type" => "xyz"
    },
    :body=>"xyz"
  }
}
iMacTia commented 1 year ago

Thank you @uday708, that explains why then! The payload you shared above is not a valid Faraday::Env hash. Here is the definition for this Struct: https://github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb#L57

As you can see, method should be in the root rather than under request. And that's not the only issue, there are others (e.g. url_path doesn't exist).

Where are you getting this e.response and why are you manually trying to create a Faraday::Env from it? This shouldn't normally be necessary when using Faraday

uday708 commented 1 year ago

Thanks @iMacTia I have figured out by removing request key from hash

iMacTia commented 1 year ago

Awesome! Thank you for confirming 🙏