{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Servant.Server.Internal.ErrorFormatter
( ErrorFormatters(..)
, ErrorFormatter
, NotFoundErrorFormatter
, DefaultErrorFormatters
, defaultErrorFormatters
, MkContextWithErrorFormatter
, mkContextWithErrorFormatter
) where
import Data.String.Conversions
(cs)
import Data.Typeable
import Network.Wai.Internal
(Request)
import Servant.API
(Capture, ReqBody)
import Servant.Server.Internal.Context
import Servant.Server.Internal.ServerError
type DefaultErrorFormatters = '[ErrorFormatters]
data ErrorFormatters = ErrorFormatters
{
ErrorFormatters -> ErrorFormatter
bodyParserErrorFormatter :: ErrorFormatter
, ErrorFormatters -> ErrorFormatter
urlParseErrorFormatter :: ErrorFormatter
, :: ErrorFormatter
, ErrorFormatters -> NotFoundErrorFormatter
notFoundErrorFormatter :: NotFoundErrorFormatter
}
defaultErrorFormatters :: ErrorFormatters
defaultErrorFormatters :: ErrorFormatters
defaultErrorFormatters = ErrorFormatters
{ bodyParserErrorFormatter :: ErrorFormatter
bodyParserErrorFormatter = ErrorFormatter
err400Formatter
, urlParseErrorFormatter :: ErrorFormatter
urlParseErrorFormatter = ErrorFormatter
err400Formatter
, headerParseErrorFormatter :: ErrorFormatter
headerParseErrorFormatter = ErrorFormatter
err400Formatter
, notFoundErrorFormatter :: NotFoundErrorFormatter
notFoundErrorFormatter = forall a b. a -> b -> a
const ServerError
err404
}
type ErrorFormatter = TypeRep -> Request -> String -> ServerError
type NotFoundErrorFormatter = Request -> ServerError
type MkContextWithErrorFormatter (ctx :: [*]) = ctx .++ DefaultErrorFormatters
mkContextWithErrorFormatter :: forall (ctx :: [*]). Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter :: forall (ctx :: [*]).
Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter Context ctx
ctx = Context ctx
ctx forall (l1 :: [*]) (l2 :: [*]).
Context l1 -> Context l2 -> Context (l1 .++ l2)
.++ (ErrorFormatters
defaultErrorFormatters forall x (xs :: [*]). x -> Context xs -> Context (x : xs)
:. Context '[]
EmptyContext)
err400Formatter :: ErrorFormatter
err400Formatter :: ErrorFormatter
err400Formatter TypeRep
_ Request
_ String
e = ServerError
err400 { errBody :: ByteString
errBody = forall a b. ConvertibleStrings a b => a -> b
cs String
e }
_RB :: Proxy ReqBody
_RB :: Proxy ReqBody
_RB = forall {k} (t :: k). Proxy t
Proxy
_C :: Proxy Capture
_C :: Proxy Capture
_C = forall {k} (t :: k). Proxy t
Proxy
_CT :: Proxy Context
_CT :: Proxy Context
_CT = forall {k} (t :: k). Proxy t
Proxy