@playerony/try-catch-wrapper
Version:
Functional try-catch wrapper.
22 lines (21 loc) • 855 B
TypeScript
/**
* @packageDocumentation Functional try-catch wrapper.
*/
/**
* try-catch wrapper for synchronous functions
*
* @param toExecute - synchronous function to execute inside of try-catch
* @param onError - synchronous function to execute when an error occurs
*
* @public
*/
export declare const tryCatchWrapper: <TData = unknown, TError = unknown>(toExecute: () => TData, onError?: ((error: TError) => void) | undefined) => void | TData;
/**
* try-catch wrapper for asynchronous functions
*
* @param toExecute - asynchronous function to execute inside of try-catch
* @param onError - asynchronous function to execute when an error occurs
*
* @public
*/
export declare const asyncTryCatchWrapper: <TData = unknown, TError = unknown>(toExecute: () => Promise<TData>, onError?: ((error: TError) => void) | undefined) => Promise<void | TData>;