I have several async callbacks which I'd like to try one after the other.
These are designed to throw an error if the asynchronous test they are running fails.
The tests check the privilege of a user from most to least. So if we're checking that a user is in a particular group, we first check if they are admin, then if they are no further checks are needed.
My instinct was to chain the catch blocks like this:
try {
await userIsAdmin;
next();
} catch(e) {
await userIsInGroup(group);
next();
} catch(e) {
console.log('User is not admin or in the group');
}
I'm about to start nesting my try's and catches but I'm starting to smell a rat.
Is this a sensible approach to sequencing multiple asynchronous operations which may or may not throw an error?
.then()
and.catch()
}
brackets?