{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Servant.Server.Internal.ErrorFormatter
( ErrorFormatters(..)
, ErrorFormatter
, NotFoundErrorFormatter
, DefaultErrorFormatters
, defaultErrorFormatters
, MkContextWithErrorFormatter
, mkContextWithErrorFormatter
) where
import Data.Kind (Type)
import Data.Typeable
import Network.Wai.Internal (Request)
import qualified Data.ByteString.Lazy.Char8 as BSL8
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
{ $sel:bodyParserErrorFormatter:ErrorFormatters :: ErrorFormatter
bodyParserErrorFormatter = ErrorFormatter
err400Formatter
, $sel:urlParseErrorFormatter:ErrorFormatters :: ErrorFormatter
urlParseErrorFormatter = ErrorFormatter
err400Formatter
, $sel:headerParseErrorFormatter:ErrorFormatters :: ErrorFormatter
headerParseErrorFormatter = ErrorFormatter
err400Formatter
, $sel:notFoundErrorFormatter:ErrorFormatters :: NotFoundErrorFormatter
notFoundErrorFormatter = ServerError -> NotFoundErrorFormatter
forall a b. a -> b -> a
const ServerError
err404
}
type ErrorFormatter = TypeRep -> Request -> String -> ServerError
type NotFoundErrorFormatter = Request -> ServerError
type MkContextWithErrorFormatter (ctx :: [Type]) = ctx .++ DefaultErrorFormatters
mkContextWithErrorFormatter :: forall (ctx :: [Type]). Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter :: forall (ctx :: [Type]).
Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter Context ctx
ctx = Context ctx
ctx Context ctx
-> Context '[ErrorFormatters]
-> Context (ctx .++ '[ErrorFormatters])
forall (l1 :: [Type]) (l2 :: [Type]).
Context l1 -> Context l2 -> Context (l1 .++ l2)
.++ (ErrorFormatters
defaultErrorFormatters ErrorFormatters -> Context '[] -> Context '[ErrorFormatters]
forall x (xs :: [Type]). x -> Context xs -> Context (x : xs)
:. Context '[]
EmptyContext)
err400Formatter :: ErrorFormatter
err400Formatter :: ErrorFormatter
err400Formatter TypeRep
_ Request
_ String
e = ServerError
err400 { errBody = BSL8.pack e }
_RB :: Proxy ReqBody
_RB :: Proxy ReqBody
_RB = Proxy ReqBody
forall {k} (t :: k). Proxy t
Proxy
_C :: Proxy Capture
_C :: Proxy Capture
_C = Proxy Capture
forall {k} (t :: k). Proxy t
Proxy
_CT :: Proxy Context
_CT :: Proxy Context
_CT = Proxy Context
forall {k} (t :: k). Proxy t
Proxy