{-# 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 :: ErrorFormatter
-> ErrorFormatter
-> ErrorFormatter
-> NotFoundErrorFormatter
-> ErrorFormatters
ErrorFormatters
{ bodyParserErrorFormatter :: ErrorFormatter
bodyParserErrorFormatter = ErrorFormatter
err400Formatter
, urlParseErrorFormatter :: ErrorFormatter
urlParseErrorFormatter = ErrorFormatter
err400Formatter
, headerParseErrorFormatter :: ErrorFormatter
headerParseErrorFormatter = ErrorFormatter
err400Formatter
, notFoundErrorFormatter :: 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 :: [*]) = ctx .++ DefaultErrorFormatters
mkContextWithErrorFormatter :: forall (ctx :: [*]). Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter :: Context ctx -> Context (MkContextWithErrorFormatter ctx)
mkContextWithErrorFormatter Context ctx
ctx = Context ctx
ctx Context ctx
-> Context '[ErrorFormatters]
-> Context (MkContextWithErrorFormatter ctx)
forall (l1 :: [*]) (l2 :: [*]).
Context l1 -> Context l2 -> Context (l1 .++ l2)
.++ (ErrorFormatters
defaultErrorFormatters ErrorFormatters -> Context '[] -> Context '[ErrorFormatters]
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 = String -> ByteString
forall a b. ConvertibleStrings a b => a -> b
cs String
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