UNPKG

callyflower

Version:

A collection of lightweight higher order functions to add customizable event handling to a function execution flow.

14 lines (13 loc) 956 B
import { OnCatchHandler } from "./types"; /** * Wraps a function with an `onCatch` event handler, allowing modification of the function's caught error. * The returned function calls the original function and applies the `onCatch` event if an error is caught. * It can be used to modify the error before it is rethrown, or to suppress the error and return a value. * * @template F - The type of the function to wrap. * @param {F} callee - The original function to wrap. * @param {OnCatchHandler<F>} onCatch - The handler invoked when an error is caught to modify the error or return a value. * @returns {F} A new function that wraps the original function with the `onCatch` event handler. */ declare const withOnCatch: <F extends (...args: any) => any>(callee: F, onCatch?: OnCatchHandler<F>) => F | ((...args: Parameters<F>) => ReturnType<F> | undefined) | ((...args: Parameters<F>) => Promise<ReturnType<F> | undefined>); export { withOnCatch };