DEV Community

[Comment from a deleted post]
Collapse
 
devdufutur profile image
Rudy Nappée • Edited

It seems difficult to read to me...

Why not just keep things simple like that?

try {
  return await findSomething(someUid);
} catch (e) {
  If (e.notFound) {
    return null;
  }
  throw e;
}
Enter fullscreen mode Exit fullscreen mode

You can still have some complex chaining and keep idiomatic async/await structure :

try {
  let res1 = await someAsyncStuff()
  let [res2, res3] = await Promise.all([
    asyncStuff1(res1),
    asyncStuff2(res1)
  ]);
  return await finalCalculation( res1, res2, res3);
} catch (e) {
  return understandWhatFailedWhyAndWhatToDoAfterwards(e);
}
Enter fullscreen mode Exit fullscreen mode