ConditionalCatch
After async/await is now a wide spread thing, there is a need to somehow catch and handle all those errors again. What in the past has been handled with an callback(err)
is now a try-catch block.
If you want to react different based on the type of error or something, I might have there something for you:
npm install conditional-catch
This will allow you to react on errors in a more fluent and functional way:
const { ConditionalCatch } = require('conditional-catch')
// ...
try {
// some action that throws errors
} catch (error) {
ConditionalCatch.createFrom(error)
.when(e => e instanceof SomeError, e => { log.error('Cought that nasty bug again which can be ignored', e); })
.handleOrThrow();
}
If you have some additions or issues feel free to open an issue or pull request on github