Created
July 9, 2023 16:33
-
-
Save arleighdickerson/c5f67df8698519ace118d2c6564d0cea to your computer and use it in GitHub Desktop.
safeInvoke(obj, path[], ...args[])
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
const invoke = new Proxy(_.invoke, { | |
apply(target, thisArg, argArray: any[]): any { | |
try { | |
return Reflect.apply(target, thisArg, argArray); | |
} catch (e) { | |
if (process.env.NODE_ENV === 'development') { | |
console.debug('[safe-invoke] discarding exception', e, ...argArray); | |
} | |
} | |
}, | |
}); | |
export default function safeInvoke(object: any, path: string[], ...args: any[]): unknown { | |
return invoke(object, path, ...args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment