File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
servant-client-ghcjs/src/Servant/Client/Internal Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change
1
+ synopsis: Fix performRequest in servant-client-ghcjs
2
+ prs: #1529
3
+
4
+ description: {
5
+
6
+ performRequest function in servant-client-ghcjs was not compatible with the
7
+ latest RunClient typeclass. Added the acceptStatus parameter and fixed the
8
+ functionality to match what servant-client provides.
9
+
10
+ }
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ instance Exception StreamingNotSupportedException where
120
120
displayException _ = " streamingRequest: streaming is not supported!"
121
121
122
122
instance RunClient ClientM where
123
- runRequest = performRequest
123
+ runRequestAcceptStatus = performRequest
124
124
throwClientError = throwError
125
125
126
126
runClientMOrigin :: ClientM a -> ClientEnv -> IO (Either ClientError a )
@@ -152,15 +152,18 @@ runClientM m = do
152
152
153
153
runClientMOrigin m (ClientEnv (BaseUrl protocol hostname port " " ))
154
154
155
- performRequest :: Request -> ClientM Response
156
- performRequest req = do
155
+ performRequest :: Maybe [ Status ] -> Request -> ClientM Response
156
+ performRequest acceptStatus req = do
157
157
xhr <- liftIO initXhr
158
158
burl <- asks baseUrl
159
159
liftIO $ performXhr xhr burl req
160
160
resp <- toResponse xhr
161
161
162
- let status = statusCode (responseStatusCode resp)
163
- unless (status >= 200 && status < 300 ) $ do
162
+ let status = responseStatusCode resp
163
+ goodStatus = case acceptStatus of
164
+ Nothing -> statusIsSuccessful status
165
+ Just good -> status `elem` good
166
+ unless goodStatus $ do
164
167
let f b = (burl, BL. toStrict $ toLazyByteString b)
165
168
throwError $ FailureResponse (bimap (const () ) f req) resp
166
169
You can’t perform that action at this time.
0 commit comments