DEV Community

Discussion on: Async + Await refactor, which do you like best?

Collapse
 
erebos-manannan profile image
Erebos Manannán

Neither is very good, as you're doing nothing to handle errors.

One requires .catch() in several places, the other a try { ... } catch (...) { ... } block or several.

Overall the await syntax is much easier to read and follow the logic, but if you have to put a try..catch around every one it quickly becomes a mess too.

Collapse
 
qm3ster profile image
Mihail Malo

I often do the following:

await fallible().catch(errorHandler)

It allows me to pipe/sidechain my errors where they truly belong, instead of breaking up my happy path logic with inline implementation of the catch block OR lambda.
If I need to abort the current function, the handler will just rethrow.

Collapse
 
wilburpowery profile image
Wilbur Powery

Yeah, I agree. As with everything, you should choose carefully 😄