Skip to content

Instantly share code, notes, and snippets.

@abegehr
Created March 27, 2020 19:27
Show Gist options
  • Save abegehr/78ff807ecb9c3cc9359a0d9b9fa1ad39 to your computer and use it in GitHub Desktop.
Save abegehr/78ff807ecb9c3cc9359a0d9b9fa1ad39 to your computer and use it in GitHub Desktop.
Promise.then().catch() vs. async, await, try, catch
async function call1() {
try {
return await promise1;
}
catch (err) {
console.warn("promise1 – Error: ", err);
}
}
async function call2() {
try {
const res = await promise1;
return res.body;
}
catch (err) {
console.warn("promise1 – Error: ", err);
}
}
Promise.all([call1(), call2()])
.then([data, body] => {…})
Promise.all([
promise1
.catch(err => console.warn("promise1 – Error: ", err)),
promise2
.then(res => res.body)
.catch(err => console.warn("promise2 – Error: ", err))
]).then([data, body] => {…})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment