Skip to content

Commit d9fce13

Browse files
committed
Add xhrErrorToText
1 parent 4ff2543 commit d9fce13

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ The `Event` of responses comes, in this case, from a function that will take the
161161
> Right a -> Right a
162162
> Left x -> Left $ f x
163163
>
164-
> xhrErrorToText = _xhrResponse_statusText . _xhrError_response
165-
>
166164

167165
```
168166

reflex-gadt-api.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ library
2525
aeson >=1.4.4 && <2.3
2626
, aeson-gadt-th >=0.2.4 && <0.3
2727
, base >=4.12 && <4.22
28-
, bytestring >=0.10.8 && <0.13
2928
, constraints-extras >=0.3.0 && <0.5
3029
, containers >=0.6 && <0.8
3130
, data-default >=0.6 && <0.9

src/Reflex/Dom/GadtApi/XHR.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ module Reflex.Dom.GadtApi.XHR where
1010
import Control.Concurrent (forkIO, newEmptyMVar, putMVar, takeMVar)
1111
import Control.Monad.IO.Class (MonadIO, liftIO)
1212
import Data.Aeson
13-
import qualified Data.ByteString.Lazy as LBS
1413
import Data.Constraint.Extras (Has, has)
1514
import Data.Functor (void)
1615
import Data.Text (Text)
17-
import qualified Data.Text.Encoding as T
1816
import GHC.Generics
1917
import Language.Javascript.JSaddle (MonadJSM)
2018
import Language.Javascript.JSaddle.Monad (runJSM, askJSM)
@@ -53,6 +51,15 @@ data XhrError = XhrError
5351
}
5452
deriving (Generic)
5553

54+
xhrErrorToText :: XhrError -> Text
55+
xhrErrorToText e =
56+
let
57+
status = _xhrResponse_statusText . _xhrError_response $ e
58+
rsp = _xhrResponse_responseText . _xhrError_response $ e
59+
in status <> case rsp of
60+
Nothing -> ""
61+
Just r -> ": " <> r
62+
5663
-- | Encodes an API request as JSON and issues an 'XhrRequest',
5764
-- and attempts to decode the response.
5865
apiRequestXhr

0 commit comments

Comments
 (0)