diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/sugar.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js index c11024e1..487c093c 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -605,6 +605,20 @@ export function decorateErrorWithCause(fn, cause) { }; } +export function conditionallySuppressError(conditionFn, callbackFn) { + return (...args) => { + try { + return callbackFn(...args); + } catch (error) { + if (conditionFn(error, ...args) === true) { + return; + } + + throw error; + } + }; +} + // Delicious function annotations, such as: // // (*bound) soWeAreBackInTheMine |