packages feed

req 3.11.0 → 3.12.0

raw patch · 4 files changed

+43/−1 lines, 4 filesdep ~http-api-data

Dependency ranges changed: http-api-data

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+## Req 3.12.0++* Add `isStatusCodeException` function.+* Add `instance HttpResponse (Network.HTTP.Client.Response ())`.+ ## Req 3.11.0  * Add the `queryParamToList` method to the `QueryParam` type class.
Network/HTTP/Req.hs view
@@ -207,6 +207,7 @@      -- * Other     HttpException (..),+    isStatusCodeException,     CanHaveBody (..),     Scheme (..),   )@@ -1971,6 +1972,16 @@   acceptHeader :: Proxy response -> Maybe ByteString   acceptHeader Proxy = Nothing +-- | This instance has been added to make it easier to inspect 'L.Response'+-- using Req's functions like 'responseStatusCode', 'responseStatusMessage',+-- etc.+--+-- @since 3.12.0+instance HttpResponse (L.Response ()) where+  type HttpResponseBody (L.Response ()) = ()+  toVanillaResponse = id+  getHttpResponse = return . void+ ---------------------------------------------------------------------------- -- Other @@ -2008,6 +2019,20 @@   deriving (Show, Typeable, Generic)  instance Exception HttpException++-- | Return 'Just' if the given 'HttpException' is wrapping a http-client's+-- 'L.StatusCodeException'. Otherwise, return 'Nothing'.+--+-- @since 3.12.0+isStatusCodeException :: HttpException -> Maybe (L.Response ())+isStatusCodeException+  ( VanillaHttpException+      ( L.HttpExceptionRequest+          _+          (L.StatusCodeException r _)+        )+    ) = Just r+isStatusCodeException _ = Nothing  -- | A simple type isomorphic to 'Bool' that we only have for better error -- messages. We use it as a kind and its data constructors as type-level
httpbin-tests/Network/HTTP/ReqSpec.hs view
@@ -49,6 +49,11 @@         blindlyThrowing (req GET httpbin NoReqBody ignoreResponse mempty)           `shouldThrow` anyException +  describe "isStatusCodeException" $+    it "extracts non-2xx response" $+      req GET (httpbin /: "foo") NoReqBody ignoreResponse mempty+        `shouldThrow` selector404ByStatusCodeException+   describe "receiving user-agent header back" $     it "works" $ do       r <-@@ -453,6 +458,13 @@     ) =     L.responseStatus response == Y.status404 && not (B.null chunk) selector404 _ = False++-- | Same as 'selector404' except that it uses 'isStatusCodeException'.+selector404ByStatusCodeException :: HttpException -> Bool+selector404ByStatusCodeException e =+  case isStatusCodeException e of+    Nothing -> False+    Just r -> responseStatusCode r == 404  -- | The empty JSON 'Object'. emptyObject :: Value
req.cabal view
@@ -1,6 +1,6 @@ cabal-version:   2.4 name:            req-version:         3.11.0+version:         3.12.0 license:         BSD-3-Clause license-file:    LICENSE.md maintainer:      Mark Karpov <markkarpov92@gmail.com>