mrkkrp / req

An HTTP client library
Other
337 stars 40 forks source link

An easy way to avoid throwing on non-200 statuses #52

Closed artempyanykh closed 5 years ago

artempyanykh commented 5 years ago

With vanilla Network.HTTP.Client one can just setRequestIgnoreStatus. It looks like that with req I'd need to define MonadHttp with handleHttpException, but this looks like too much hassle if I just want to run requests in IO and handle all responses irregardless of their status codes.

Am I missing something in the config?

mrkkrp commented 5 years ago

If you don’t want to define an instance of MonadHttp you can always use runReq and pass HttpConfig there directly. In the config you’ll need to set httpConfigCheckResponse to something like \_ _ _ -> Nothing.

mrkkrp commented 5 years ago

Does this answer your question? Can we close this one?

artempyanykh commented 5 years ago

Ah, I see. Thank you very much for helping @mrkkrp, good to close!

mrkkrp commented 5 years ago

This is also shown in the docs and readme 😉

artempyanykh commented 5 years ago

@mrkkrp right, just checked Haddock and found mentions of httpConfigCheckResponse. However, in README I couldn't find anything except

Just define handleHttpException accordingly when making your monad instance of MonadHttp and it will play together seamlessly.

Maybe it's worth adding a small note or example? TBH, I was pretty surprised to receive an exception on non-200 response, not exactly the default of a least surprise.

Anyway, sorry for the silly question. I'm new to Haskell and its ecosystem and failed to figure out from the first try how http-client and req play together ¯\_(ツ)_/¯

mrkkrp commented 5 years ago

Ah, sorry I just was thinking about runReq itself vs defining a new instance. Never mind.