-
Notifications
You must be signed in to change notification settings - Fork 14
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
Simplify the From/ToJSON instances for Envelope #5
Comments
Err, actually, I realized the |
I'm really on the fence about this. Personally, I like that the However, I totally understand that some users don't like the all responses wrapped with either It's somewhat hacky, but how about a solution like this: Make the Instead, the So you could import just the import Servant.Checked.Exceptions.Internal.Envelope (Envelope)
import Servant.Checked.Exceptions.Internal.Servant (Throws) If you did this, you could write your own |
Another solution would be to split |
As far as the However, one small question I have is the following: Does it ever make sense to send back an error with a HTTP 200 response? I personally can't think of a time it would make sense, but I wouldn't be surprised if someone somewhere has to work with an API like this. |
I’m not fond of any of the solutions involving orphans, especially since it could be extremely confusing if any other libraries want to depend on Ultimately, this is a minor issue for what I’m doing so far, but if I were to use this for a production application in a professional setting, there are reasons I would really need complete control over the JSON bodies in my responses. With the current API, it’s impossible to get rid of the wrappers, while simplified instances would at least allow users to opt-in. It’s still not a very good solution, though. Perhaps an alternative approach would be to allow |
You’re right that this is totally feasible for certain use-cases. Personally, I’m not sure it’s worth supporting this if it’s a ton of additional work (since this use case is pretty pathological), but this is all theoretical right now anyway, since |
This is a good idea. It would allow a user to use a different type if they really wanted. If you (or someone else) wanted to implement this, I would accept the PR.
I agree with this. It's somewhat a problem with Servant as it is, but I don't think |
Another idea could be to parameterize both data DataAndErr deriving Typeable
data Throwing' phantom
type Throwing = Throwing DataAndErr
data Envelope' phantom es a = ...
type Envelope es a = Envelope DataAndErr es a
instance ToJSON (Envelope' DataAndErr es a) where ... The majority of the servant-checked-exceptions library could stay as-is. All functions currently dealing with an The end user should be able to create their own type (similar to |
We also find this feature problematic. We're currently working around it by using overlapping instances:
but it's not quite ideal. The |
@23Skidoo Yes, I would accept a patch adding a phantom parameter to |
Just to add to @lexi-lambda points, the current approach breaks integration with https://hackage.haskell.org/package/servant-swagger and https://github.com/felixmulder/servant-openapi , where API specs are generated without the wrapper in mind, and the codegen tools such as https://github.com/OpenAPITools/openapi-generator generate clients that are unable to communicate with Servant servers that use Checked Exceptions. |
Currently,
Envelope
wraps errors with{ "err": ... }
and successes with{ "data": ... }
. These cannot be customized by the user, and they prevent some structures I would like to be able to return. I think theToJSON
instance should simply defer to the underlyingToJSON
instances without doing any wrapping to avoid imposing requirements on the user’s responses.I also question whether or not the
FromJSON
instance is even a good idea at all. I’m not sure when I would want to construct anEnvelope
from JSON input, and as the documentation mentions, it’s problematic if the instances are ambiguous. My preference would simply be to eliminate theFromJSON
instance entirely.The text was updated successfully, but these errors were encountered: