module Network.Wai.Predicate.Error
( Error
, Reason (..)
, err
, e400
, e405
, e406
, e415
, e500
, status
, message
, reason
, source
, labels
, setStatus
, setMessage
, setReason
, setSource
, addLabel
, isReasonOf
) where
import Data.ByteString (ByteString)
import Network.HTTP.Types.Status
data Reason
= NotAvailable
| TypeError
deriving (Eq, Show)
data Error = Error
{ status :: !Status
, message :: Maybe ByteString
, reason :: Maybe Reason
, source :: Maybe ByteString
, labels :: [ByteString]
} deriving (Eq, Show)
err :: Status -> Error
err s = Error s Nothing Nothing Nothing []
setStatus :: Status -> Error -> Error
setStatus s e = e { status = s }
setMessage :: ByteString -> Error -> Error
setMessage m e = e { message = Just m }
setReason :: Reason -> Error -> Error
setReason r e = e { reason = Just r }
setSource :: ByteString -> Error -> Error
setSource s e = e { source = Just s }
addLabel :: ByteString -> Error -> Error
addLabel l e = e { labels = l : labels e }
isReasonOf :: Reason -> Error -> Bool
isReasonOf r e = maybe False (r ==) (reason e)
e400, e405, e406, e415, e500 :: Error
e400 = err status400
e405 = err status405
e406 = err status406
e415 = err status415
e500 = err status500