Being new to typescript / javascript, I have limited knowledge about promises. My current scenario involves creating three distinct promises within a cloud-function and subsequently returning them using
Promise.all([promise1, promise2, promise3])
. Each of these promises is generated within a function that includes the statement "return Promise...".
I am curious as to whether adding ".catch" inside these functions will impact the functionality of Promise.all
. Does it matter if someServiceThatCreatesPromise()
is returned with or without .catch()
?
Code
export async function myCloudFirestoreFunction() {
try {
const myFirstPromise = createFirstPromise()
const mySecondPromise = createSecondPromise()
const thirdPromise = createThirdPromise()
return Promise.all([
myFirstPromise,
mySecondPromise,
myThirdPromise
]);
} catch (err) {
functions.logger.err(`Something bad happened, See: ${(err as Error).message}`
}
}
// What happens when using `.catch` vs. not using it?
function createFirstPromise() {
return someServiceThatCreatesPromise().catch((err) => { // LOGGING });
}
// What happens when using `.catch` vs. not using it?
function createSecondPromise() {
return someServiceThatCreatesPromise().catch((err) => { // LOGGING });
}
// What happens when using `.catch` vs. not using it?
function createThirdPromise() {
return someServiceThatCreatesPromise().catch((err) => { // LOGGING });
}