Skip to content

Commit d93ebc5

Browse files
committed
Update readme, include note on request vs response errors
1 parent 6b98be6 commit d93ebc5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ main = launchAff $ do
4545

4646
(`defaultRequest` is a record value that has all the required fields pre-set for convenient overriding when making a request.)
4747

48-
Or use of a number of helpers for common `get`, `post`, `put`, `delete`, and `patch` cases:
48+
There are also a number of helpers for common `get`, `post`, `put`, `delete`, and `patch` cases:
4949

5050
```purescript
5151
import Affjax.RequestBody as RequestBody
@@ -62,7 +62,15 @@ main = launchAff $ do
6262
Right json -> log $ "POST /api response: " <> J.stringify json
6363
```
6464

65-
See the module documentation for a full list of these helpers and their variations.
65+
See the [main module documentation](https://pursuit.purescript.org/packages/purescript-affjax/docs/Affjax) for a full list of these helpers and their variations.
66+
67+
## Error handling
68+
69+
There are two ways an Affjax request can fail: there's either some problem with the request itself, or the result that comes back is not as expected.
70+
71+
For the first case, these errors will be things like the URL being invalid or the server not existing, and will occur in the `Aff` error channel. The [`try`](https://pursuit.purescript.org/packages/purescript-aff/docs/Effect.Aff#v:try) function can lift these errors out of the error channel so the result of a request becomes `Aff (Either Error (Response _))`.
72+
73+
The latter case occurs when we did get a response for the request, but the result that came back could not be handled in the way that was expected. In these situations the `body` value of the `Response` will be a `Left` value with the error message describing what went wrong.
6674

6775
## Module documentation
6876

0 commit comments

Comments
 (0)