Skip to content

Commit 5390219

Browse files
committed
feat: handle 'Request path contains unescaped characters' as custom error -> add BadUrlError and change test
1 parent 0d30f28 commit 5390219

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: src/Affjax.purs

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ data Error
9191
| ResponseBodyError ForeignError (Response Foreign)
9292
| TimeoutError
9393
| RequestFailedError
94+
| BadUrlError String
9495
| XHROtherError Exn.Error
9596

9697
printError :: Error -> String
@@ -103,6 +104,8 @@ printError = case _ of
103104
"There was a problem making the request: timeout"
104105
RequestFailedError ->
105106
"There was a problem making the request: request failed"
107+
BadUrlError url ->
108+
"There was a problem with the url: " <> url
106109
XHROtherError err ->
107110
"There was a problem making the request: " <> Exn.message err
108111

@@ -198,6 +201,7 @@ request req =
198201
in Left $
199202
if message == timeoutErrorMessageIdent then TimeoutError
200203
else if message == requestFailedMessageIdent then RequestFailedError
204+
else if message == "Request path contains unescaped characters" then BadUrlError req.url
201205
else XHROtherError err
202206

203207
ajaxRequest :: Nullable Foreign -> AjaxRequest a

Diff for: test/Main.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ main = void $ runAff (either (\e -> logShow e *> Exn.throwException e) (const $
110110

111111
A.log "Testing invalid url"
112112
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"
113+
AX.BadUrlError url → assertEq "/фыва" url
114+
other → logAny' other *> assertFail "Expected a BadUrlError"

0 commit comments

Comments
 (0)