UNPKG

@snipsonian/core

Version:

Core/base reusable javascript code snippets

16 lines (15 loc) 387 B
export default function conditionalCatch({ actionToExecute, onError, shouldCatchErrors = false, }) { if (shouldCatchErrors) { try { return actionToExecute(); } catch (error) { if (typeof onError === 'function') { return onError(error); } } } else { return actionToExecute(); } }