servant-server-0.20.2: A family of combinators for defining webservices APIs and serving them

Safe Haskell | None
Language | Haskell2010

Servant.Server.Internal.ErrorFormatter

Synopsis

- data ErrorFormatters = ErrorFormatters {
  - bodyParserErrorFormatter :: ErrorFormatter
  - urlParseErrorFormatter :: ErrorFormatter
  - headerParseErrorFormatter :: ErrorFormatter
  - notFoundErrorFormatter :: NotFoundErrorFormatter
  }
- type ErrorFormatter = TypeRep -> Request -> String -> ServerError
- type NotFoundErrorFormatter = Request -> ServerError
- type DefaultErrorFormatters = '[ErrorFormatters]
- defaultErrorFormatters :: ErrorFormatters
- type MkContextWithErrorFormatter (ctx :: [Type]) = ctx .++ DefaultErrorFormatters
- mkContextWithErrorFormatter :: forall (ctx :: [Type]). Context ctx -> Context (MkContextWithErrorFormatter ctx)

# Documentation

data ErrorFormatters #

A collection of error formatters for different situations.

If you need to override one of them, use `defaultErrorFormatters` with record update syntax.

Constructors

ErrorFormatters |
Fields bodyParserErrorFormatter :: ErrorFormatter Format error from parsing the request body. urlParseErrorFormatter :: ErrorFormatter Format error from parsing url parts or query parameters. headerParseErrorFormatter :: ErrorFormatter Format error from parsing request headers. notFoundErrorFormatter :: NotFoundErrorFormatter Format error for not found URLs.

type ErrorFormatter = TypeRep -> Request -> String -> ServerError #

A custom formatter for errors produced by parsing combinators like `ReqBody` or `Capture`.

A `TypeRep` argument described the concrete combinator that raised the error, allowing formatter to customize the message for different combinators.

A full `Request` is also passed so that the formatter can react to `Accept` header, for example.

type NotFoundErrorFormatter = Request -> ServerError #

This formatter does not get neither `TypeRep` nor error message.

type DefaultErrorFormatters = '[ErrorFormatters] #

`Context` that contains default error formatters.

defaultErrorFormatters :: ErrorFormatters #

Default formatters will just return HTTP 400 status code with error message as response body.

type MkContextWithErrorFormatter (ctx :: [Type]) = ctx .++ DefaultErrorFormatters #

mkContextWithErrorFormatter :: forall (ctx :: [Type]). Context ctx -> Context (MkContextWithErrorFormatter ctx) #