http-exceptions icon indicating copy to clipboard operation
http-exceptions copied to clipboard

Make 'code' method configurable

Open SirRawlins opened this issue 6 years ago • 1 comments

A great looking gem. 👍

I was hoping to use wrap_and_check around some sendgrid-ruby requests, which return non-2XX response codes rather than raising exceptions. However the SendGrid::Response object exposes its status code through status_code() rather than code().

I can monkey-patch sendgrid-ruby to provide the code() method, but I wonder if this might be a nice configuration option for http-exceptions instead - maybe something like:

Http::Exceptions.configure do |config|
    config.status_code_method = :status_code
end

Or, perhaps an option to wrap_and_check would be even better?

response = Http::Exceptions.wrap_and_check(status_code_method: :status_code) do
    client.mail._('send').post(request_body: message.to_json)
end

If you think this might be useful, I'd be happy to wrap up a PR for it.

SirRawlins avatar Dec 09 '19 11:12 SirRawlins

Thanks for opening this issue!

marvin-rfbot[bot] avatar Dec 09 '19 11:12 marvin-rfbot[bot]