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

servant-client doesn't allow HasClient instances to handle non-2xx responses #1253

Open
mheinzel opened this issue Dec 12, 2019 · 8 comments
Labels
zurihac2020 https://github.com/haskell-servant/servant/issues/1299

Comments

@mheinzel
Copy link
Contributor

Hi,

When handling a response with a non-2xx status code, the RunClient instance currently directly throws a ClientError FailureResponse. This contains the raw response body as a ByteString, but since it's an error, it short-circuits and doesn't get parsed in the HasClient instance.
The same thing applies to other client libraries like servant-http-streams and servant-client-ghcjs.

This means that combinators can't specify how to handle non-2xx responses, severely limiting the usefulness of some libraries, see e.g. this issue in servant-checked-exceptions.

I know there are some related discussions and work being done that could move information about expected return codes to the type level, but I'm not sure what the expected timeline for that is.

Do you think it would be worth doing something simple now that allows users of existing solutions like servant-checked-exceptions to get access to the responses they care about and handle them as they want?

One possibility I see would be to adapt the ClientEnv configuration records to allow supplying the (currently hardcoded) function that decides which responses are considered successful.
I created a simple proof of concept or servant-client and could do the same for the other client libraries here (plus adding test cases and some docs) if you are interested.

Thanks!

@alpmestan
Copy link
Contributor

This is an interesting idea. Thoughts, @phadej?

Note that there's servant-uverb which is an attempt at supplying a verb combinator that lets you declare all the outcomes of a route explicitly. See https://github.com/wireapp/servant-uverb

@phadej
Copy link
Contributor

phadej commented Dec 19, 2019 via email

@mheinzel
Copy link
Contributor Author

so then status checks have to overridable per http-lib supported: i.e. In both servant-client and servant-http-streams, perfectly also servant-jssaddle

Exactly, that's the idea. I agree that a solution in servant-client-core would be nicer, but it seems like that would require a breaking change of the RunClient typeclass definition itself.

If you think the per-client extension of ClientEnv is the way to go, I will go ahead and create a PR with changes for -client, -http-streams, -jssaddle and -client-ghcjs. Maybe another one in the servant-js repo.

@phadej
Copy link
Contributor

phadej commented Dec 20, 2019

PR would be great

@fisx fisx added the zurihac2020 https://github.com/haskell-servant/servant/issues/1299 label May 18, 2020
@fisx
Copy link
Member

fisx commented May 18, 2020

related: #841

@mheinzel
Copy link
Contributor Author

Thanks for the reminder. I still have an in-progress branch for this, almost finished. I can turn it into a PR next weekend.

@fisx fisx mentioned this issue May 18, 2020
@coderfromhere
Copy link

Hi, stumbled upon this thread while using the client for checking non-2xx payloads. Any progress with the aforementioned PR?

@mheinzel
Copy link
Contributor Author

Yeah, I just forgot about it at some point. I'll try wrapping it up in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zurihac2020 https://github.com/haskell-servant/servant/issues/1299
Projects
None yet
Development

No branches or pull requests

5 participants