⚠️ Internal: This API is not publically exported by the
package.
- runSafeAsync<T>(functionToRun, ...functionParams): Promise<{
error?: never;
hasError: false;
value: Awaited<ReturnType<T>>;
} | {
error: unknown;
hasError: true;
value: undefined;
}> Type Parameters
T extends ((...args) => Promise<unknown>)
Parameters
functionToRun: T
Rest
...functionParams: Parameters<T>
Returns Promise<{
error?: never;
hasError: false;
value: Awaited<ReturnType<T>>;
} | {
error: unknown;
hasError: true;
value: undefined;
}>
Run a function without the risk that the function will throw an error. Errors will be returned as part of the return object instead of throwing.