I have multiple Node-mssql module requests for mssql-database inside an async function in Javascript...
What is the best method to generally wait for the results and check if all of them passed? The requests kind of belong together, so they have to pass all together or if one fails, then all fail.
let result1 = await requestObject.query(someQuery);
let result2 = await requestObject.query(otherQuery);
Normally, I use a .then().catch clause,
.then((result) => res.status(200).send(result)).catch(err => res.status(404).send(err));
but I want to avoid this because I have 2 queries and I can only use it on my last query because after sending a response I cannot send another response.
what's the best way to check if the return status of both my queries was OK or if an error happened? because they are executed kind of synchronously in the above order.
I think my approaches would either be:
- I could check result1 and result2 for some status code or if they are not empty (depending on my query?)
- I would do a .then() Promise-chain, where I execute my second query inside the .then()-block of the first resulted query, and at the end I do a .catch(), so it should automatically catch all errors that occured during any query, is that right?