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

Added type synonym for error in mimeUnrender and ResultStream #1053

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions servant/src/Servant/API/ContentTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,20 @@ instance TL.TypeError ('TL.Text "No instance for (), use NoContent instead.")
-- >>> type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] Int
--
class Accept ctype => MimeUnrender ctype a where
mimeUnrender :: Proxy ctype -> ByteString -> Either String a
mimeUnrender :: Proxy ctype -> ByteString -> Either BodyDecodingError a
mimeUnrender p = mimeUnrenderWithType p (contentType p)

-- | Variant which is given the actual 'M.MediaType' provided by the other party.
--
-- In the most cases you don't want to branch based on the 'M.MediaType'.
-- See <https://github.com/haskell-servant/servant/pull/552 pr552> for a motivating example.
mimeUnrenderWithType :: Proxy ctype -> M.MediaType -> ByteString -> Either String a
mimeUnrenderWithType :: Proxy ctype -> M.MediaType -> ByteString -> Either BodyDecodingError a
mimeUnrenderWithType p _ = mimeUnrender p

{-# MINIMAL mimeUnrender | mimeUnrenderWithType #-}

type BodyDecodingError = String

class AllCTUnrender (list :: [*]) a where
canHandleCTypeH
:: Proxy list
Expand Down
4 changes: 3 additions & 1 deletion servant/src/Servant/API/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ instance ToStreamGenerator [a] a where
-- @ResultStream@ that captures the setup, takedown, and incremental logic for
-- a read, being an IO continuation that takes a producer of Just either values
-- or errors that terminates with a Nothing.
newtype ResultStream a = ResultStream { runResultStream :: forall b. (IO (Maybe (Either String a)) -> IO b) -> IO b }
newtype ResultStream a = ResultStream { runResultStream :: forall b. (IO (Maybe (Either BodyDecodingError a)) -> IO b) -> IO b }

type BodyDecodingError = String

-- | FromResultStream is intended to be implemented for types such as Conduit, Pipe, etc. By implementing this class, all such streaming abstractions can be used directly on the client side for talking to streaming endpoints.
class FromResultStream a b | b -> a where
Expand Down