Commit 16f95c05 authored by Alex Navasardyan's avatar Alex Navasardyan

adding docs about "fail" handler; removing redundant .call in fail()

parent b452c89d
...@@ -116,7 +116,7 @@ Errors also propagate: ...@@ -116,7 +116,7 @@ Errors also propagate:
```javascript ```javascript
getJSON("/posts.json").then(function(posts) { getJSON("/posts.json").then(function(posts) {
}).fail(function(error) { }).then(null, function(error) {
// since no rejection handler was passed to the // since no rejection handler was passed to the
// first `.then`, the error propagates. // first `.then`, the error propagates.
}); });
...@@ -131,11 +131,22 @@ getJSON("/post/1.json").then(function(post) { ...@@ -131,11 +131,22 @@ getJSON("/post/1.json").then(function(post) {
return getJSON(post.commentURL); return getJSON(post.commentURL);
}).then(function(comments) { }).then(function(comments) {
// proceed with access to posts and comments // proceed with access to posts and comments
}).fail(function(error) { }).then(null, function(error) {
// handle errors in either of the two requests // handle errors in either of the two requests
}); });
``` ```
You can also use `fail` for error handling, which is a shortcut for
`then(null, rejection)`, like so:
```javascript
getJSON("/post/1.json").then(function(post) {
return getJSON(post.commentURL);
}).fail(function(error) {
// handle errors
});
```
## Arrays of promises ## Arrays of promises
Sometimes you might want to work with many promises at once. If you Sometimes you might want to work with many promises at once. If you
......
...@@ -123,7 +123,7 @@ Promise.prototype = { ...@@ -123,7 +123,7 @@ Promise.prototype = {
}, },
fail: function(fail) { fail: function(fail) {
return this.then.call(this, null, fail); return this.then(null, fail);
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment