medikoo/deferred

Introduce `catchByCode`

medikoo opened this issue · 0 comments

So we can narrow callback to be called only in case of specific error type:

promise.catchByCode('ENOENT'); // bypass ENOENT errors

promise.catchByCode('ENOENT', function (e) {
  // File not found, proceed with alternative strategy:
  ..
}); 

Consider support for multiple codes handling e.g.:

promise.catchByCode({
  ENOENT: null, // bypass
  EMFILE: function (e) {
    // Maximum number of open file descriptors reached...
    ...
  }
});