Safe Haskell | None |
---|---|
Language | Haskell2010 |
contains the ErrorReport data type and tools for constructing error reports, along with the ReportableError typeclass.
- data ErrorReport = ErrorReport {}
- simpleErrorReport :: Text -> ErrorReport
- errorReportWithMessage :: Text -> Text -> ErrorReport
- errorReportWithDetails :: ToJSON d => Text -> d -> ErrorReport
- fullErrorReport :: ToJSON d => Text -> Text -> d -> ErrorReport
- single :: ToJSON a => Text -> Maybe a -> Value
- statusFormat :: Format Status
- maybeFormat :: forall m r a. m -> Holey Builder Builder (a -> m) -> Holey m r (Maybe a -> r)
- errorReportFormat :: Format Text -> Format Text -> Format Value -> Format ErrorReport
- boolFormat :: Format Bool
- mkIndent :: Int64 -> Builder
- simpleJsonValue :: Format Value
- plaintextErrorReportFormat :: forall b. Holey Builder b (Status -> ErrorReport -> b)
- renderPlainTextErrorReport :: Status -> ErrorReport -> Text
- pFormat :: Buildable a => Int64 -> Format a
- htmlErrorReportFormat :: forall b. Holey Builder b (Status -> ErrorReport -> b)
- renderHTMLErrorReport :: Status -> ErrorReport -> Text
- class ReportableError e where
- reportError :: Status -> e -> ByteString -> ResponseBody
- reportAsErrorReport :: (a -> ErrorReport) -> Status -> a -> ByteString -> ResponseBody
- newtype JsonParseError = JsonParseError {}
ErrorReport data
data ErrorReport Source
an error report is something that can be sent back as a response without having to worry about it too much.
ToJSON ErrorReport | the ErrorReport json representation has the fields "reason", "message", and "details". Absent message and details values are represented as null in json. |
ReportableError ErrorReport |
building error reports
simpleErrorReport :: Text -> ErrorReport Source
constructor for the simplest error report
errorReportWithMessage :: Text -> Text -> ErrorReport Source
constructor for error report with reason and message
errorReportWithDetails :: ToJSON d => Text -> d -> ErrorReport Source
constructor for error report with reason and details
fullErrorReport :: ToJSON d => Text -> Text -> d -> ErrorReport Source
error report with all the fixings
single :: ToJSON a => Text -> Maybe a -> Value Source
construct a single-key json object if the value is present
rendering ErrorReports
statusFormat :: Format Status Source
format a Status into a single string.
for example, "200 OK", or "404 Not Found"
maybeFormat :: forall m r a. m -> Holey Builder Builder (a -> m) -> Holey m r (Maybe a -> r) Source
i am not sure what the type means, but you pass this a default string and a format for a thing, and it gives you a formatter for maybe that thing.
format-builders
:: Format Text | format for the reason |
-> Format Text | format for the message, if there is one |
-> Format Value | format for the details, if any |
-> Format ErrorReport |
build a format for an error report
simpleJsonValue :: Format Value Source
format a JSON value in a simple way. let Aeson handle the formatting.
formatters for plain text
plaintextErrorReportFormat :: forall b. Holey Builder b (Status -> ErrorReport -> b) Source
the plaintext error report format
tries to be somewhat yaml
renderPlainTextErrorReport :: Status -> ErrorReport -> Text Source
renders error report as plain text
formatters for HTML
htmlErrorReportFormat :: forall b. Holey Builder b (Status -> ErrorReport -> b) Source
the html format
renderHTMLErrorReport :: Status -> ErrorReport -> Text Source
renders error report as HTML
ReportableError class
class ReportableError e where Source
type class for responses that report errors.
:: Status | the http error code that'll be sent |
-> e | the error to be reported |
-> ByteString | the Accept header on the receiving end |
-> ResponseBody | the http body to send. |
ReportableError UnicodeException | this instance constructs an |
ReportableError JsonParseError | |
ReportableError ErrorReport |
instances etc
reportAsErrorReport :: (a -> ErrorReport) -> Status -> a -> ByteString -> ResponseBody Source
newtype JsonParseError Source
newtype wrapper for the error messages produced while parsing json so we can have a ReportableError instance for it.