Make ServantErr throwable

This commit is contained in:
Robert Klotzner 2016-02-26 12:27:19 +01:00
parent d46cde913c
commit b1ff2beb8a

View file

@ -2,8 +2,10 @@
{-# LANGUAGE RecordWildCards #-}
module Servant.Server.Internal.ServantErr 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)
@ -11,7 +13,10 @@ data ServantErr = ServantErr { errHTTPCode :: Int
, errReasonPhrase :: String
, errBody :: LBS.ByteString
, errHeaders :: [HTTP.Header]
} deriving (Show, Eq, Read)
} deriving (Show, Eq, Read, Typeable)
-- Make ServantErr throwable:
instance Exception ServantErr
responseServantErr :: ServantErr -> Response
responseServantErr ServantErr{..} = responseLBS status errHeaders errBody