Error handling on async + callback codebases
if you have both newer async/await code ref async article as well as callback style code:
- you might be wondering where the error handlers are for the callback code
- you might have an async await with a try catch at the very top of the file
- you might be working on a file far down below that calls a library that has callbacks for error handling, but nobody handled the callback in the legacy code.
what you need to remember is this
as long as something returns new Promise(...), or you know the library method/function call returns a Promise, your async/await code will be able to catch them all at the top.
the catch block on top is like en error-catching net that covers all eventualities (regarding errors), and does not require you to interface with older async code to handle them individually.
steps to find out if your callback functions have error
- find out where that function is called
- repeat step 1 until you find a
try/catch - if the catch block either handles all errors generically or handles errors by type, you're golden.