-
Notifications
You must be signed in to change notification settings - Fork 14
Polymorphic envelope #36
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
base: master
Are you sure you want to change the base?
Polymorphic envelope #36
Conversation
Introduces variants with `'` for the combinators `Throws`, `Throwing`, `NoThrow` and the `VerbWithErr` types. These variants accept an `envel` type of kind `[*] -> * -> *` which is the error envelope to be used. The non-primed combinators are aliases for those, called with `Envelope`. A typeclass `EnvelopeStatus` is introduced, allowing retrieval of HTTP status codes from the envelope.
This commit adds a wrapper around `Envelope` with a flat JSON representation.
@BrechtSerckx Thanks for working on this. Could you add a small example of using this here: https://github.com/cdepillabout/servant-checked-exceptions/tree/master/servant-checked-exceptions/example |
Sure! I'll look into it. |
@cdepillabout I added documentation generation for |
Thanks for adding an example. I've been busy lately, but I'll try to get around to doing a good review of this sometime soon. |
@BrechtSerckx While I think the approach in this PR is more general, I'm wondering if the approach described in #5 (comment) would be easier to implement and maintain. Almost all of the current code would basically be the same, but Are there things that you want to do that wouldn't be enabled by this approach? |
fooHandler (Foo 1) = fmap FlatEnvelope . pureErrEnvelope $ Err1 | ||
fooHandler (Foo 2) = fmap FlatEnvelope . pureErrEnvelope $ Err2 | ||
fooHandler (Foo n) = fmap FlatEnvelope . pureSuccEnvelope . FooBar $ "foo: " <> show n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not being able to directly use pureErrEnvelope
and pureSuccEnvelope
when using a different envelope type is pretty inconvenient.
I guess all of the functions exported by Servant.Checked.Exceptions.Envelope
would have to be wrapped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not strictly necessary. My current implementation uses it like this: I program using normal Envelope
s (EnvelopeT
), and only right before returning the return value in the endpoint handler, I wrap it in a FlatEnvelope
. Combined with an existing helper function, this makes the conversion of my server-side code only a oneliner.
Both I'll see if I can compare pros/cons:
Contra:
Contra:
Personally, I don't think having a an
At the moment, no. |
@BrechtSerckx Thanks for the summary. I think the approach implemented in this PR (adding an However, making users have to create wrappers around Off the top of my head, I guess we could introduce a type-class for figuring out the correct I was thinking that just adding an additional phantom type to |
This PR solves #5 by generalizing the envelope used, as in this comment. I chose for this approach as it is more general than a phantom type parameter, and allows for using custom envelopes.
In the first commit, primed variants of existing combinators are defined, accepting an
envel
parameter of kind[*] -> * -> *
. The existing combinators are redefined as aliases, providingenvel = Envelope
.In the second commit, a
FlatEnvelope
type is defined as a wrapper aroundEnvelope
with a flat JSON representation.Tests pass, and it does the job in my pet project. I don't use docs though.
Feedback is certainly welcome!