httprb / http

HTTP (The Gem! a.k.a. http.rb) - a fast Ruby HTTP client with a chainable API, streaming support, and timeouts
MIT License
3.01k stars 321 forks source link

New feature: RaiseError #792

Closed c960657 closed 1 week ago

c960657 commented 1 month ago

The library raises errors if the server does various unexpected things, e.g. TooManyRedirectsError, but it does not raise if the HTTP status code indicates a client error (4xx) or server (5xx) error.

Sometimes you are interested in non-successful responses, and sometimes you just want to treat them as any other error triggered by the server.

This PR adds a new feature that will raise an exception on status codes representing an error. If you want to skip this for specific codes, you can specify them in the ignore option.

c960657 commented 1 week ago

Thanks for the review. I have addressed your comments.

ixti commented 1 week ago

Thank you!