medikoo / deferred

Modular and fast Promises implementation for JavaScript
ISC License
365 stars 20 forks source link

Introduce `catchByCode` #40

Open medikoo opened 9 years ago

medikoo commented 9 years ago

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...
    ...
  }
});