-
-
Notifications
You must be signed in to change notification settings - Fork 412
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
Configurable combinator errors #685
Comments
Hi, I've stumbled into this problem, as many servant users did before me. I see that these issues gathered a lot of nice idea, however no one volunteered to implement them. Therefore I'd like to ask if the PR has any chance to get merged, if I manage to make one. Basically, I'm willing to implement I hope to make it so that users won't have to define custom (#732 is still unrelated, and it's lower priority since one can use cc @fisx. |
we're almost done implementing this: https://github.com/wireapp/servant-uverb it's in a different repo, but we are planning to merge it into servant, and since the maintainers are all pretty much on board... would you be ok with this approach? wanna join us on zurihac? :) |
Nice to hear that, @fisx! |
Now I've had a look at But this issue is about error messages generated by combinators like Unless you are not going to go this way too, my proposal still stands. |
I agree we'd ideally have both! Re: the question of I also am not sure what I was thinking with the sum, rather than product, type (in One thing to be attentive to is backwards compatibility, both with the current version of servant, and with potential new versions that throw new types of error. Ideally, then, if there is some product type:
Then the |
Thanks @jkarni, I'm more inclined to implement the second approach, with separate types for handlers, since What do you think? Can I try and come up with a WIP PR for this? |
Sorry @maksbotan I didn't pay attention when I replied earlier. Yes, this is an orthogonal issue and I should really find the time to read up on the details above... |
Okay, I will try to work on this, maybe the next week. |
Currently there is no way for Servant users to customize formatting of error messages that arise when combinators can't parse URL or request body, apart from reimplementing those combinators for themselves or using middlewares. This commit adds a possibility to specify custom error formatters through Context. Fixes haskell-servant#685
Currently there is no way for Servant users to customize formatting of error messages that arise when combinators can't parse URL or request body, apart from reimplementing those combinators for themselves or using middlewares. This commit adds a possibility to specify custom error formatters through Context. Fixes haskell-servant#685
Currently there is no way for Servant users to customize formatting of error messages that arise when combinators can't parse URL or request body, apart from reimplementing those combinators for themselves or using middlewares. This commit adds a possibility to specify custom error formatters through Context. Fixes haskell-servant#685
Currently there is no way for Servant users to customize formatting of error messages that arise when combinators can't parse URL or request body, apart from reimplementing those combinators for themselves or using middlewares. This commit adds a possibility to specify custom error formatters through Context. Fixes haskell-servant#685
Problem
Currently combinators throw errors in a non-configurable way. If JSON decoding fails, for example, it's hard to get the error message to look the way you want. As another example, one would need to use hacky middleware to make 404 pages one likes.
Proposed approach
One of the exciting things about
Context
is that it makes it much easier to configure combinators, and makes fixing this relatively trivial. The way I conceive of it is:Or:
And then we would provide a default
BasicErrorFormatting
(or set of error datatypes) that mimics current behavior, and makeserve
use it.serveWithContext
would allow configuration.Open questions
Accept
headers, though it's not clear how that would workIO
before the response (i.e.,NotFound (String -> IO ServantErr
). The main advantage that I can see would be logging, though perhaps this is well covered by middlewareThe text was updated successfully, but these errors were encountered: