3 ms·
I usually catch rejections then turn them into a resolution as an object with an 'errno' property. That way, your handler always gets called, rejections are
by akira2501 4y ago
I usually catch rejections then turn them into a resolution as an object with an 'errno' property. That way, your handler always gets called, rejections are never generated up to the top level, and you can move the error handling into your consumer very easyily.
const thing = await fn();
if (thing?.errno) {
//handle error
return;
}
// handle result
Maybe I spent too much time writing C code. There are very few times when I actually want a rejection to take an entirely different path through my code, and this feels like the correct way to write it.