respond-1.1.0: process and route HTTP requests and generate responses on top of WAI

Safe HaskellNone
LanguageHaskell2010

Web.Respond.Types.Errors

Contents

Description

contains the ErrorReport data type and tools for constructing error reports, along with the ReportableError typeclass.

Synopsis

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.

Constructors

ErrorReport 

Fields

erReason :: Text

the reason for the error. should describe the type of error that occurred to the api consumer.

erMessage :: Maybe Text

a message that might explain why the error occurred.

erDetails :: Maybe Value

any details about the error that could be useful

Instances

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

errorReportFormat Source

Arguments

:: 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.

Methods

reportError Source

Arguments

:: 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.

instances etc

newtype JsonParseError Source

newtype wrapper for the error messages produced while parsing json so we can have a ReportableError instance for it.

Constructors

JsonParseError