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

Problems with error statuses for REST client (2.1.0) #1009

Open
brevio-nicolay opened this issue Nov 29, 2022 · 4 comments
Open

Problems with error statuses for REST client (2.1.0) #1009

brevio-nicolay opened this issue Nov 29, 2022 · 4 comments

Comments

@brevio-nicolay
Copy link

Hi, thanks for the great library!

First, some versions for reference:

Ruby version: 3.1.0
Webmock version: 3.18.1
REST client version: 2.1.0

When I try to mock a single call to any URL and return any status other than 200 I get the following error from within the rest-client gem (rest-client-2.1.0/lib/restclient/exceptions.rb:123 to be precise):

'http_code': undefined method 'code' for "404 Not Found":String

Example to reproduce:

url = 'https://example.com'
Webmock::API.stub_request(:get, url).to_return(status: 404)
RestClient.get(url)

200 works fine:

url = 'https://example.com'
Webmock::API.stub_request(:get, url).to_return(status: 200)
RestClient.get(url) # no problems

Now, I'm not sure whether I'm just overlooking something painfully obvious, or if this is an issue with Webmock or REST client - does Webmock not support REST client 2.1.0?

@bblimke
Copy link
Owner

bblimke commented Aug 20, 2023

@brevio-nicolay I have tested the same setup, Ruby 3.2.2 or Ruby 3.1.4 and in both cases I correctly get 404 Not Found (RestClient::NotFound). Do you still experience the issue?

@ErikSchierboom
Copy link

ErikSchierboom commented Oct 19, 2023

I have found the same issue, although the 404 one does work. But using 400 or 429 will fail.

Versions used:

Webmock: 3.19.1
rest-client: 2.1.0
Ruby: 3.2.1

@lgo
Copy link

lgo commented Jan 17, 2024

Same issues with Ruby 3.2.2.

    rest-client (2.1.0)
      http-accept (>= 1.7.0, < 2.0)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 4.0)
      netrc (~> 0.8)

    webmock (3.19.1)
      addressable (>= 2.8.0)
      crack (>= 0.3.2)
      hashdiff (>= 0.4.0, < 2.0.0)

And this is the stacktrace. I'll look into getting a minimal reproducing example.

/usr/local/lib/ruby/gems/3.2.0/gems/rest-client-2.1.0/lib/restclient/exceptions.rb:123:in `http_code': undefined method `code' for "HTTP status code 4":String (NoMethodError)

        @response.code.to_i
                 ^^^^^
Did you mean?  encode
        from /usr/local/lib/ruby/gems/3.2.0/gems/rest-client-2.1.0/lib/restclient/exceptions.rb:158:in `default_message'
        from /usr/local/lib/ruby/gems/3.2.0/gems/rest-client-2.1.0/lib/restclient/exceptions.rb:142:in `message'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:991:in `message'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:612:in `block in to_s'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:611:in `map'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:611:in `to_s'
        from /usr/local/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/test_unit/reporter.rb:109:in `color_output'
        from /usr/local/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/test_unit/reporter.rb:23:in `record'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:926:in `block in record'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:925:in `each'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:925:in `record'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:374:in `run_one_method'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:361:in `block (2 levels) in run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:360:in `each'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:360:in `block in run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:408:in `on_signal'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:395:in `with_info_handler'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:359:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/test_unit/line_filtering.rb:10:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:185:in `block in __run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:185:in `map'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:185:in `__run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:162:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest.rb:86:in `block in autorun'

@bblimke
Copy link
Owner

bblimke commented Feb 6, 2024

@lgo @ErikSchierboom are you able to provide a sample code that reproduces the issue?

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

No branches or pull requests

4 participants