Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document what responses result in exceptions #125

Open
aztecrex opened this issue May 27, 2018 · 1 comment
Open

Document what responses result in exceptions #125

aztecrex opened this issue May 27, 2018 · 1 comment

Comments

@aztecrex
Copy link

Suggest that the documentation be more explicit on what responses result in exception.

In particular, what status codes result in an exception? What statuses are the responsibility of client code?

I see a lens for checkResponse that I suspect gives some control. But in defaults the value for it is Nothing and yet get throws exceptions on non-200 statuses. I can't find much documentation of that option, either.

@jez
Copy link

jez commented May 31, 2018

Hey @aztecrex! I just ran into this too (I was very surprised that non 200 statuses were raised as exceptions). This is how I ended up using checkResponse:

noExceptions :: W.Options
noExceptions = W.defaults & W.checkResponse .~ (Just $ \_ _ -> return ())

When I started using this for requests, it didn't raise exceptions anymore.

@bos I'd love to see a quick section in <www.serpentine.com/wreq/tutorial.html> referencing this snippet. Most of the other http client's I'm familiar with (Python's requests, JavaScript's fetch, ...) don't raise. A quick note about how to get back to the no-raise behavior would be great.


Curious about what's going on here? It looks like the checkResponse option is just forwarded to the underlying http-client library that wreq abstracts over. In particular, if we look at that package's documentation, we see:

-- | Modify the request so that non-2XX status codes do not generate a runtime
-- 'StatusCodeException'.
--
-- @since 0.4.29
setRequestIgnoreStatus :: Request -> Request
setRequestIgnoreStatus req = req { checkResponse = \_ _ -> return () }

So that's where I got the idea for the snippet I posted above.

http://hackage.haskell.org/package/http-client-0.5.12.1/docs/Network-HTTP-Client.html#v:setRequestIgnoreStatus

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

No branches or pull requests

2 participants