Skip to content

Commit

Permalink
Merge pull request #163 from akheron/issue-158
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
garyb authored Nov 11, 2018
2 parents f6d95e9 + 22ffaa5 commit f927c62
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ synchronous code.
## Dealing with Failure

`Aff` has error handling baked in, so ordinarily you don't have to worry
about it.
about it. For control-flow exceptions, it's advised to use `ExceptT`
instead throwing errors in the `Aff` context. The support for errors
mainly exists to notify you when very bad things happen.

When you need to deal with failure, you have a few options.
However, when you need to deal with `Aff` errors, you have a few options.

1. **Alt**
2. **MonadError**
Expand All @@ -139,15 +141,21 @@ example = do

#### 2. MonadError

`Aff` has a `MonadError` instance, which comes with two functions:
`catchError`, and `throwError`.
`Aff` has a `MonadError` instance, which comes with three functions:
`try`, `catchError`, and `throwError`.

These are defined in
[purescript-transformers](http://github.com/purescript/purescript-transformers).
Here's an example of how you can use them:

```purescript
example = do
tryExample = do
result <- try $ Ajax.get "http://foo.com"
case result of
Left err -> pure ""
Right resp -> pure resp.body
catchThrowExample = do
resp <- Ajax.get "http://foo.com" `catchError` \_ -> pure defaultResponse
when (resp.statusCode /= 200) do
throwError myErr
Expand Down

0 comments on commit f927c62

Please sign in to comment.