Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Code from Servant.Server.Internal, modified very slightly to allow for returning json errors instead of plaintext.
Synopsis
- data ReqBodyCustomError' (mods :: [Type]) (list :: [ct]) (tag :: Symbol) (a :: Type)
- type ReqBodyCustomError = ReqBodyCustomError' '[Required, Strict]
- class MakeCustomError (tag :: Symbol) (a :: Type) where
- makeCustomError :: String -> ServerError
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
RoutesToPaths rest => RoutesToPaths (ReqBodyCustomError' mods list tag a :> rest :: Type) Source # | |
Defined in Servant.API.Extended | |
HasOpenApi (ReqBody' '[Required, Strict] cts a :> api) => HasOpenApi (ReqBodyCustomError cts tag a :> api :: Type) Source # | |
Defined in Servant.API.Extended | |
(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 |
Defined in Servant.API.Extended type ServerT (ReqBodyCustomError' mods list tag a :> api) m Source # 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 # | |
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 |
type ReqBodyCustomError = ReqBodyCustomError' '[Required, Strict] Source #
class MakeCustomError (tag :: Symbol) (a :: Type) where Source #
Custom parse error for bad request bodies.
makeCustomError :: String -> ServerError Source #