Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #163

Merged
merged 1 commit into from
Nov 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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