Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
Middleware between Wai
-
Servant to accommodate raw error responses
returned by servant. See also
handleRawError
.
Synopsis
- handleRawError :: ( Request -> ServerError -> ServerError ) -> Middleware
Documentation
:: ( Request -> ServerError -> ServerError ) |
Convert a raw response into something that better fits the application error |
-> Middleware |
Make sure every error is converted to a suitable application-level error.
There are many cases where Servant will handle errors itself and reply to a client without even disturbing the application. This is both handy and clunky since our application return errors in a specific format (e.g. JSON, XML ...).
This is the case for instance if the client hits a non-exiting endpoint of the API, or if the client requests an invalid content-type, etc ...
Ideally, we would like clients to be able to expect one and only one format,
so this middleware allows for manipulating the response returned by a Wai
application (what servant boils down to) and adjust the response when
necessary. So, any response with or without payload but no content-type will
trigger the
convert
function and offer the caller to adjust the response as
needed.