Function invokeWithErrorHandlingFactory

  • Creates a function factory with error handling capabilities

    Parameters

    • handleError: Fn

      Error handling function to process exceptions during execution

    Returns ((handler, context?, args?) => any)

    Returns a new function that can execute target functions with automatic error handling

      • (handler, context?, args?): any
      • Parameters

        • handler: Fn
        • Optional context: unknown
        • Optional args: unknown[]

        Returns any

    Example

    const errorHandler = (error) => console.error(error);
    const safeExecute = invokeWithErrorHandlingFactory(errorHandler);

    // Execute regular function
    safeExecute(() => { throw new Error('test') });

    // Execute async function
    safeExecute(async () => { throw new Error('async test') });