Skip to content

Instantly share code, notes, and snippets.

@ohgyun
Last active January 3, 2016 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohgyun/8451170 to your computer and use it in GitHub Desktop.
Save ohgyun/8451170 to your computer and use it in GitHub Desktop.
Promises Error Handling
var p = function () {
var d = Q.defer();
d.reject();
return d.promise;
};
# Case 1
p()
.then(function () {
console.log('A');
}, function () {
console.log('B');
});
//--> B
# Case 2
P()
.then(function () {
console.log('A');
})
.fail(function () {
console.log('B');
});
//--> B
# Case 3
p()
.then(function () [
console.log('A');
})
.fail(function () {
console.log('B');
})
.then(function () {
console.log('C');
});
//--> B, C
# Case 4
p()
.then(function () {
console.log('A');
})
.fail(function () {
console.log('B');
})
.fail(function () {
console.log('C');
})
.then(function () {
console.log('D');
});
//--> B, D
# Case 5
p()
.fail(function () {
console.log('A');
})
.then(function () {
console.log('B');
})
.fail(function () {
console.log('C');
})
.then(function () {
console.log('D')
});
//--> A, B, D
# Case 6
p()
.then(function () {
console.log('A');
})
.then(function () {
console.log('B');
})
.then(function () {
console.log('C');
})
.fail(function () {
console.log('D');
});
//--> D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment