{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Servant.Server.Internal.ServerError where
import Control.Exception
(Exception)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy as LBS
import Data.Typeable
(Typeable)
import qualified Network.HTTP.Types as HTTP
import Network.Wai
(Response, responseLBS)
data ServerError = ServerError
{ ServerError -> Int
errHTTPCode :: Int
, ServerError -> String
errReasonPhrase :: String
, ServerError -> ByteString
errBody :: LBS.ByteString
, :: [HTTP.Header]
}
deriving (Int -> ServerError -> ShowS
[ServerError] -> ShowS
ServerError -> String
(Int -> ServerError -> ShowS)
-> (ServerError -> String)
-> ([ServerError] -> ShowS)
-> Show ServerError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServerError] -> ShowS
$cshowList :: [ServerError] -> ShowS
show :: ServerError -> String
$cshow :: ServerError -> String
showsPrec :: Int -> ServerError -> ShowS
$cshowsPrec :: Int -> ServerError -> ShowS
Show, ServerError -> ServerError -> Bool
(ServerError -> ServerError -> Bool)
-> (ServerError -> ServerError -> Bool) -> Eq ServerError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServerError -> ServerError -> Bool
$c/= :: ServerError -> ServerError -> Bool
== :: ServerError -> ServerError -> Bool
$c== :: ServerError -> ServerError -> Bool
Eq, ReadPrec [ServerError]
ReadPrec ServerError
Int -> ReadS ServerError
ReadS [ServerError]
(Int -> ReadS ServerError)
-> ReadS [ServerError]
-> ReadPrec ServerError
-> ReadPrec [ServerError]
-> Read ServerError
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServerError]
$creadListPrec :: ReadPrec [ServerError]
readPrec :: ReadPrec ServerError
$creadPrec :: ReadPrec ServerError
readList :: ReadS [ServerError]
$creadList :: ReadS [ServerError]
readsPrec :: Int -> ReadS ServerError
$creadsPrec :: Int -> ReadS ServerError
Read, Typeable)
instance Exception ServerError
responseServerError :: ServerError -> Response
responseServerError :: ServerError -> Response
responseServerError ServerError{Int
String
[Header]
ByteString
errHeaders :: [Header]
errBody :: ByteString
errReasonPhrase :: String
errHTTPCode :: Int
errHeaders :: ServerError -> [Header]
errBody :: ServerError -> ByteString
errReasonPhrase :: ServerError -> String
errHTTPCode :: ServerError -> Int
..} = Status -> [Header] -> ByteString -> Response
responseLBS Status
status [Header]
errHeaders ByteString
errBody
where
status :: Status
status = Int -> ByteString -> Status
HTTP.mkStatus Int
errHTTPCode (String -> ByteString
BS.pack String
errReasonPhrase)
err300 :: ServerError
err300 :: ServerError
err300 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
300
, errReasonPhrase :: String
errReasonPhrase = String
"Multiple Choices"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err301 :: ServerError
err301 :: ServerError
err301 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
301
, errReasonPhrase :: String
errReasonPhrase = String
"Moved Permanently"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err302 :: ServerError
err302 :: ServerError
err302 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
302
, errReasonPhrase :: String
errReasonPhrase = String
"Found"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err303 :: ServerError
err303 :: ServerError
err303 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
303
, errReasonPhrase :: String
errReasonPhrase = String
"See Other"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err304 :: ServerError
err304 :: ServerError
err304 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
304
, errReasonPhrase :: String
errReasonPhrase = String
"Not Modified"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err305 :: ServerError
err305 :: ServerError
err305 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
305
, errReasonPhrase :: String
errReasonPhrase = String
"Use Proxy"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err307 :: ServerError
err307 :: ServerError
err307 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
307
, errReasonPhrase :: String
errReasonPhrase = String
"Temporary Redirect"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err400 :: ServerError
err400 :: ServerError
err400 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
400
, errReasonPhrase :: String
errReasonPhrase = String
"Bad Request"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err401 :: ServerError
err401 :: ServerError
err401 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
401
, errReasonPhrase :: String
errReasonPhrase = String
"Unauthorized"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err402 :: ServerError
err402 :: ServerError
err402 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
402
, errReasonPhrase :: String
errReasonPhrase = String
"Payment Required"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err403 :: ServerError
err403 :: ServerError
err403 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
403
, errReasonPhrase :: String
errReasonPhrase = String
"Forbidden"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err404 :: ServerError
err404 :: ServerError
err404 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
404
, errReasonPhrase :: String
errReasonPhrase = String
"Not Found"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err405 :: ServerError
err405 :: ServerError
err405 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
405
, errReasonPhrase :: String
errReasonPhrase = String
"Method Not Allowed"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err406 :: ServerError
err406 :: ServerError
err406 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
406
, errReasonPhrase :: String
errReasonPhrase = String
"Not Acceptable"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err407 :: ServerError
err407 :: ServerError
err407 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
407
, errReasonPhrase :: String
errReasonPhrase = String
"Proxy Authentication Required"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err409 :: ServerError
err409 :: ServerError
err409 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
409
, errReasonPhrase :: String
errReasonPhrase = String
"Conflict"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err410 :: ServerError
err410 :: ServerError
err410 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
410
, errReasonPhrase :: String
errReasonPhrase = String
"Gone"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err411 :: ServerError
err411 :: ServerError
err411 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
411
, errReasonPhrase :: String
errReasonPhrase = String
"Length Required"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err412 :: ServerError
err412 :: ServerError
err412 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
412
, errReasonPhrase :: String
errReasonPhrase = String
"Precondition Failed"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err413 :: ServerError
err413 :: ServerError
err413 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
413
, errReasonPhrase :: String
errReasonPhrase = String
"Request Entity Too Large"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err414 :: ServerError
err414 :: ServerError
err414 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
414
, errReasonPhrase :: String
errReasonPhrase = String
"Request-URI Too Large"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err415 :: ServerError
err415 :: ServerError
err415 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
415
, errReasonPhrase :: String
errReasonPhrase = String
"Unsupported Media Type"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err416 :: ServerError
err416 :: ServerError
err416 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
416
, errReasonPhrase :: String
errReasonPhrase = String
"Request range not satisfiable"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err417 :: ServerError
err417 :: ServerError
err417 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
417
, errReasonPhrase :: String
errReasonPhrase = String
"Expectation Failed"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err418 :: ServerError
err418 :: ServerError
err418 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
418
, errReasonPhrase :: String
errReasonPhrase = String
"I'm a teapot"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err422 :: ServerError
err422 :: ServerError
err422 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
422
, errReasonPhrase :: String
errReasonPhrase = String
"Unprocessable Entity"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err500 :: ServerError
err500 :: ServerError
err500 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
500
, errReasonPhrase :: String
errReasonPhrase = String
"Internal Server Error"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err501 :: ServerError
err501 :: ServerError
err501 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
501
, errReasonPhrase :: String
errReasonPhrase = String
"Not Implemented"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err502 :: ServerError
err502 :: ServerError
err502 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
502
, errReasonPhrase :: String
errReasonPhrase = String
"Bad Gateway"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err503 :: ServerError
err503 :: ServerError
err503 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
503
, errReasonPhrase :: String
errReasonPhrase = String
"Service Unavailable"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err504 :: ServerError
err504 :: ServerError
err504 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
504
, errReasonPhrase :: String
errReasonPhrase = String
"Gateway Time-out"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}
err505 :: ServerError
err505 :: ServerError
err505 = ServerError :: Int -> String -> ByteString -> [Header] -> ServerError
ServerError { errHTTPCode :: Int
errHTTPCode = Int
505
, errReasonPhrase :: String
errReasonPhrase = String
"HTTP Version not supported"
, errBody :: ByteString
errBody = ByteString
""
, errHeaders :: [Header]
errHeaders = []
}