Skip to content

Conversation

eisukeyeongjo
Copy link

I think this is a better behavior for ActiveResource::ConnectionError#message.
This fix enables to return a message which is given in the argument when it is initialized.

irb(main):004:0> e = ActiveResource::ConnectionError.new(response, "Custom error message with response code => #{response.code}")
=> #<ActiveResource::ConnectionError: Custom error message with response code => 999>
irb(main):005:0> e.message
=> "Custom error message with response code => 999"
irb(main):006:0> c = ActiveResource::Connection.new('')
=> #<ActiveResource::Connection:0x000055ff3f0aa340 @bearer_token=nil, @password=nil, @user=nil, @proxy=nil, @site=#<URI::...
irb(main):007:0> c.send(:handle_response, response)
Traceback (most recent call last):
        6: from /usr/local/bin/irb:23:in `<main>'
        5: from /usr/local/bin/irb:23:in `load'
        4: from /usr/local/lib/ruby/gems/3.0.0/gems/irb-1.3.0/exe/irb:11:in `<top (required)>'
        3: from (irb):7:in `<main>'
        2: from (irb):8:in `rescue in <main>'
        1: from /usr/local/bundle/gems/activeresource-5.1.1/lib/active_resource/connection.rb:161:in `handle_response'
ActiveResource::ConnectionError (Unknown response code: 999)

@rafaelfranca rafaelfranca merged commit 3536074 into rails:master Mar 25, 2021
@eisukeyeongjo
Copy link
Author

eisukeyeongjo commented Mar 31, 2021

@rafaelfranca Thank you so much for merging this PR 🙏

@eisukeyeongjo eisukeyeongjo deleted the fix-connection-error-message branch March 26, 2022 02:59
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.

2 participants