Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to servant 0.18 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions servant-jsaddle.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: servant-jsaddle
version: 0.16
version: 0.18
synopsis:
automatic derivation of querying functions for servant webservices for jsaddle

Expand Down Expand Up @@ -46,7 +46,7 @@ library
-- Bundled with GHC: Lower bound to not force re-installs
-- text and mtl are bundled starting with GHC-8.4
build-depends:
base >=4.9 && <4.14
base >=4.9 && <4.15
, bytestring >=0.10.8.1 && <0.11
, containers >=0.5.7.1 && <0.7
, mtl >=2.2.2 && <2.3
Expand All @@ -58,7 +58,7 @@ library

-- Servant dependencies.
-- Strict dependency on `servant-client-core` as we re-export things.
build-depends: servant-client-core >=0.16 && <0.16.1
build-depends: servant-client-core >=0.18.3 && <0.18.4
build-depends:
base-compat >=0.10.5 && <0.12
, case-insensitive >=1.2.0.0 && <1.3
Expand Down
17 changes: 10 additions & 7 deletions src/Servant/Client/Internal/JSaddleXhrClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import qualified Language.Javascript.JSaddle.Types as JSaddle
import Network.HTTP.Media
(renderHeader)
import Network.HTTP.Types
(ResponseHeaders, http11, mkStatus, renderQuery, statusCode)
(ResponseHeaders, Status, http11, mkStatus, renderQuery, statusCode)
import System.IO
(hPutStrLn, stderr)

Expand Down Expand Up @@ -120,9 +120,9 @@ instance Alt ClientM where

instance RunClient ClientM where
throwClientError = throwError
runRequest r = do
runRequestAcceptStatus acceptStatus r = do
d <- ClientM askDOM
performRequest d r
performRequest acceptStatus d r

runClientM :: ClientM a -> ClientEnv -> DOM (Either ClientError a)
runClientM cm env = runExceptT $ flip runReaderT env $ fromClientM cm
Expand Down Expand Up @@ -156,16 +156,19 @@ getDefaultBaseUrl = do

pure (BaseUrl protocol hostname port "")

performRequest :: DOMContext -> Request -> ClientM Response
performRequest domc req = do
performRequest :: Maybe [Status] -> DOMContext -> Request -> ClientM Response
performRequest acceptStatus domc req = do
xhr <- JS.newXMLHttpRequest `runDOM` domc
burl <- asks baseUrl
fixUp <- asks fixUpXhr
performXhr xhr burl req fixUp `runDOM` domc
resp <- toResponse domc xhr

let status = statusCode (responseStatusCode resp)
unless (status >= 200 && status < 300) $
let status = responseStatusCode resp
goodStatus = case acceptStatus of
Nothing -> statusCode status >= 200 && statusCode status < 300
Just good -> status `elem` good
unless goodStatus $
throwError $ mkFailureResponse burl req resp

pure resp
Expand Down