on master help sign in
Record accessors for ServantError
commit8015906b53816d004a59f24d53f3797d3e3e96a3 authorTimo von Holtz <tvh@anchor.com.au> dateMon 9 Mar 2015, 08:37 (12 years ago) parentba46ecc
1 file changed+22−6
src/Servant/Common/Req.hs+22−6
src/Servant/Common/Req.hs+22−6
@@ -28,11 +28,27 @@ import System.IO.Unsafe
2828import qualified Network.HTTP.Client as Client
2929
3030data ServantError
31− = FailureResponse Status MediaType ByteString
32− | DecodeFailure String MediaType ByteString
33− | UnsupportedContentType MediaType ByteString
34− | ConnectionError HttpException
35− | InvalidContentTypeHeader String
31+ = FailureResponse
32+ { responseStatus :: Status
33+ , responseContentType :: MediaType
34+ , responseBody :: ByteString
35+ }
36+ | DecodeFailure
37+ { decodeError :: String
38+ , responseContentType :: MediaType
39+ , responseBody :: ByteString
40+ }
41+ | UnsupportedContentType
42+ { responseContentType :: MediaType
43+ , responseBody :: ByteString
44+ }
45+ | ConnectionError
46+ { connectionError :: HttpException
47+ }
48+ | InvalidContentTypeHeader
49+ { responseContentTypeHeader :: ByteString
50+ , responseBody :: ByteString
51+ }
3652 deriving (Show)
3753
3854data Req = Req
@@ -139,7 +155,7 @@ performRequest reqMethod req isWantedStatus reqHost = do
139155 ct <- case lookup "Content-Type" $ Client.responseHeaders response of
140156 Nothing -> pure $ "application"//"octet-stream"
141157 Just t -> case parseAccept t of
142− Nothing -> left . InvalidContentTypeHeader . cs $ t
158+ Nothing -> left $ InvalidContentTypeHeader (cs t) body
143159 Just t' -> pure t'
144160 unless (isWantedStatus status_code) $
145161 left $ FailureResponse status ct body