-
-
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
newtype instead of bare string in MimeUnrender / ResultStream? #999
Comments
ContentTypeError? BodyDecodingError? 😞 I'd probably be happy with a type alias. |
Swapped String error to type synonym Resolves haskell-servant#999
Swapped String error to type synonym Resolves haskell-servant#999
Just made two type synonyms, one per module, with the name |
So, we're using servant for our REST API, where our clients are ensured everything from the API is going to be JSON. Now, we've got custom json validation on our side, and I've implemented : data ReadJSON
-- | Describes the "Accept" header required to be able to process requests of this type.
instance Accept ReadJSON where
contentType _ = "application" // "json" /: ("charset", "utf-8")
-- | /Unrender/ a value from incoming HTTP data (`ByteString`)
instance JSONRead a => MimeUnrender ReadJSON a where
mimeUnrender _ bs = do
v <- eitherDecode bs -- aeson
decodeJSONEitherText v & _Left %~ T.unpack -- JSONRead Now, what I'd like to do is be able to have an equivalent of class IsServantAPIErr err where
displayErr :: err -> String
errJSON :: err -> Value
class (IsServantAPIErr (UnrenderErr a), Accept a) => MyMimeUnrender a where
type UnrenderErr a -- assoc. type that indicates the error type
mimeUnrender :: ByteString -> Either (UnrenderErr a) a
What would be the best way to achieve this? Is there something I can do with the current system to implement something to this effect? |
Currently we have
I think that we should have a wrapper over that
String
. The same error is also inResultStream
definition:If
newrype
is too much at once, I'll be already happy with a type alias. I have no good candidate for the name though.The text was updated successfully, but these errors were encountered: