Skip to content

Commit 0d30f28

Browse files
committed
feat: handle 'Request path contains unescaped characters' as custom error -> add initial test
1 parent 2c2e6e6 commit 0d30f28

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/Main.purs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
1717
import Effect.Class (liftEffect)
1818
import Effect.Class.Console as A
1919
import Effect.Console (log, logShow)
20-
import Effect.Exception (error, throwException)
20+
import Effect.Exception as Exn
2121
import Foreign.Object as FO
2222

2323
foreign import logAny :: forall a. a -> Effect Unit
@@ -30,7 +30,7 @@ logAny' :: forall a. a -> Aff Unit
3030
logAny' = liftEffect <<< logAny
3131

3232
assertFail :: forall a. String -> Aff a
33-
assertFail = throwError <<< error
33+
assertFail = throwError <<< Exn.error
3434

3535
assertMsg :: String -> Boolean -> Aff Unit
3636
assertMsg _ true = pure unit
@@ -51,7 +51,7 @@ assertEq x y =
5151
when (x /= y) $ assertFail $ "Expected " <> show x <> ", got " <> show y
5252

5353
main :: Effect Unit
54-
main = void $ runAff (either (\e -> logShow e *> throwException e) (const $ log "affjax: All good!")) do
54+
main = void $ runAff (either (\e -> logShow e *> Exn.throwException e) (const $ log "affjax: All good!")) do
5555
let ok200 = StatusCode 200
5656
let notFound404 = StatusCode 404
5757

@@ -105,5 +105,10 @@ main = void $ runAff (either (\e -> logShow e *> throwException e) (const $ log
105105
-- assertEq (Just "test=test") (lookupHeader "Set-Cookie" res.headers)
106106

107107
A.log "Testing cancellation"
108-
forkAff (AX.post_ mirror (Just (RequestBody.string "do it now"))) >>= killFiber (error "Pull the cord!")
108+
forkAff (AX.post_ mirror (Just (RequestBody.string "do it now"))) >>= killFiber (Exn.error "Pull the cord!")
109109
assertMsg "Should have been canceled" true
110+
111+
A.log "Testing invalid url"
112+
AX.get ResponseFormat.string "/фыва" >>= assertLeft >>= case _ of
113+
AX.XHROtherError error → assertEq "Request path contains unescaped characters" (Exn.message error)
114+
other → logAny' other *> assertFail "Expected a XHROtherError"

0 commit comments

Comments
 (0)