on master help sign in
Merge pull request #740 from stevana/client/include-request-in-failure-response

Include the request that failed in FailureResponse.

commit4ae8b1898f5ebe2724f5263389ece1b2679dbc62 authorOleg Grenrus <oleg.grenrus@iki.fi> dateMon 15 May 2017, 12:32 (9 years ago) parent018a38c29c9d85
2 files changed+10−4
servant-client/src/Servant/Common/Req.hs+9−3 servant-client/test/Servant/ClientSpec.hs+1−1
servant-client/src/Servant/Common/Req.hs+9−3
@@ -49,7 +49,8 @@ import Web.HttpApiData
4949
5050data ServantError
5151 = FailureResponse
52− { responseStatus :: Status
52+ { failingRequest :: UrlReq
53+ , responseStatus :: Status
5354 , responseContentType :: MediaType
5455 , responseBody :: ByteString
5556 }
@@ -72,7 +73,7 @@ data ServantError
7273 deriving (Show, Typeable)
7374
7475instance Eq ServantError where
75− FailureResponse a b c == FailureResponse x y z =
76+ FailureResponse _ a b c == FailureResponse _ x y z =
7677 (a, b, c) == (x, y, z)
7778 DecodeFailure a b c == DecodeFailure x y z =
7879 (a, b, c) == (x, y, z)
@@ -86,6 +87,11 @@ instance Eq ServantError where
8687
8788instance Exception ServantError
8889
90+data UrlReq = UrlReq BaseUrl Req
91+
92+instance Show UrlReq where
93+ show (UrlReq url req) = showBaseUrl url ++ reqPath req ++ "?" ++ show (qs req)
94+
8995data Req = Req
9096 { reqPath :: BS.Builder
9197 , qs :: QueryText
@@ -252,7 +258,7 @@ performRequest reqMethod req = do
252258 Nothing -> throwError $ InvalidContentTypeHeader (cs t) body
253259 Just t' -> pure t'
254260 unless (status_code >= 200 && status_code < 300) $
255− throwError $ FailureResponse status ct body
261+ throwError $ FailureResponse (UrlReq reqHost req) status ct body
256262 return (status_code, body, ct, hdrs, response)
257263
258264performRequestCT :: MimeUnrender ct result => Proxy ct -> Method -> Req
servant-client/test/Servant/ClientSpec.hs+1−1
@@ -372,7 +372,7 @@ failSpec = beforeAll (startWaiApp failServer) $ afterAll endWaiApp $ do
372372 let (_ :<|> getDeleteEmpty :<|> _) = client api
373373 Left res <- runClientM getDeleteEmpty (ClientEnv manager baseUrl)
374374 case res of
375− FailureResponse (HTTP.Status 404 "Not Found") _ _ -> return ()
375+ FailureResponse _ (HTTP.Status 404 "Not Found") _ _ -> return ()
376376 _ -> fail $ "expected 404 response, but got " <> show res
377377
378378 it "reports DecodeFailure" $ \(_, baseUrl) -> do