extended-0.1.0: Extended versions of common modules
Safe HaskellSafe-Inferred
LanguageGHC2021

Servant.API.Extended

Description

Code from Servant.Server.Internal, modified very slightly to allow for returning json errors instead of plaintext.

Synopsis

Documentation

data ReqBodyCustomError' (mods :: [Type]) (list :: [ct]) (tag :: Symbol) (a :: Type) Source #

Like ReqBody', but takes parsers that throw ServerError, not String. tag is used to select a MakeCustomError instance.

FUTUREWORK: this does not reflect the changes we make to the error responses wrt. the ReqBody' instance. however, in order to fix that, we would need to get more information out of the MakeCustomError instance and into ReqBodyCustomError'. Perhaps something like data ReqBody (mods :: [*]) (headers :: ...) (status :: ...) (list :: [ct]) (tag :: Symbol) (a :: *). and then we'll trip over issues similar to this one: https://github.com/wireapp/servant-uverb/blob/3647c488a88137d3ec2583b518bda59ee7072278/servant-uverb/src/Servant/API/UVerb.hs#L33-L57

FUTUREWORK: this approach is not ideal because it makes it hard to avoid orphan instances.

FUTUREWORK: parser failures currently can't have custom monad effects like logging, since they are run inside DelayedIO. we can either work around this by writing a middleware that inspects the response and logs conditionally what it finds in the body (bad for streaming and performance!), or re-wire more of the servant internals (unclear how hard that'll be).

See also: https://github.com/haskell-servant/servant/issues/353

Instances

Instances details
RoutesToPaths rest => RoutesToPaths (ReqBodyCustomError' mods list tag a :> rest :: Type) Source # 
Instance details

Defined in Servant.API.Extended

HasOpenApi (ReqBody' '[Required, Strict] cts a :> api) => HasOpenApi (ReqBodyCustomError cts tag a :> api :: Type) Source # 
Instance details

Defined in Servant.API.Extended

Methods

toOpenApi :: Proxy (ReqBodyCustomError cts tag a :> api) -> OpenApi Source #

(MakeCustomError tag a, AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods)) => HasServer (ReqBodyCustomError' mods list tag a :> api :: Type) context Source #

Variant of the ReqBody' instance that takes a ServerError as argument instead of a String. This gives the caller more control over error responses.

Instance details

Defined in Servant.API.Extended

Associated Types

type ServerT (ReqBodyCustomError' mods list tag a :> api) m Source #

Methods

route :: Proxy (ReqBodyCustomError' mods list tag a :> api) -> Context context -> Delayed env (Server (ReqBodyCustomError' mods list tag a :> api)) -> Router env Source #

hoistServerWithContext :: Proxy (ReqBodyCustomError' mods list tag a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (ReqBodyCustomError' mods list tag a :> api) m -> ServerT (ReqBodyCustomError' mods list tag a :> api) n Source #

type ServerT (ReqBodyCustomError' mods list tag a :> api :: Type) m Source # 
Instance details

Defined in Servant.API.Extended

type ServerT (ReqBodyCustomError' mods list tag a :> api :: Type) m = If (FoldLenient mods) (Either ServerError a) a -> ServerT api m

class MakeCustomError (tag :: Symbol) (a :: Type) where Source #

Custom parse error for bad request bodies.