mollie / mollie-api-ruby

Mollie API client for Ruby
http://www.mollie.com
BSD 2-Clause "Simplified" License
81 stars 42 forks source link

Mollie::RequestError should include response #165

Closed moiristo closed 6 months ago

moiristo commented 11 months ago

When a rate limit error occurs, I'd like to read out the 'retry-after' header. Unfortunately, the actual response (including headers) is not passed when the Mollie::RequestError is raised:

https://github.com/mollie/mollie-api-ruby/blob/bde1a0be0ed58d15f5560e6e442941bc0a3425ab/lib/mollie/client.rb#L137

I think it makes sense to pass the original response?

justincase commented 11 months ago

We could add http_code and http_headers to the exception object. Similar to https://github.com/rest-client/rest-client/blob/2c72a2e77e2e87d25ff38feba0cf048d51bd5eca/lib/restclient/exceptions.rb#L129.

moiristo commented 11 months ago

That would be fine. That exception class also has an accessor for the response of course. I'm not sure if the plan in that case is to set http_code and http_headers based on response data and still drop the original response itself?

justincase commented 11 months ago

I'd prefer users don't rely on an implementation detail such as the underlying HTTP library. Is there anything you might need besides the code, headers, and body?

moiristo commented 11 months ago

@justincase no, I don't think so. If the http library needs to be interchangeable, then I think adding http_headers is indeed the way to go.