Skip to content

Instantly share code, notes, and snippets.

@Gfast2
Created December 22, 2019 16:47
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 Gfast2/1c71012c7509ba89dfaea9b06f390b74 to your computer and use it in GitHub Desktop.
Save Gfast2/1c71012c7509ba89dfaea9b06f390b74 to your computer and use it in GitHub Desktop.
Promise.resolve("original")
.then(
resolved => {
console.log(`Upper Promise resolved, message is "${resolved}"`);
throw "stage1 throw error"; // -> This thrown error will trigger the following then()'s rejected function, but not in this then()'s rejection.
return "stage1 succeed";
},
rejected => {
console.log(`Upper Promise rejected, message is "${rejected}"`);
// throw "stage1 failed" // -> will let the following then() receive a rejected Promise with this string
return "stage1 failed"; // -> will let the following then() receive a resolved Promise with this string
}
)
.then(
resolved => {
console.log(`Upper Promise resolved, message is "${resolved}"`);
return "stage2 succeed";
},
rejected => {
console.log(`Upper Promise rejected, message is "${rejected}"`);
return "stage2 failed";
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment