Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 37x 41x 13x 13x 13x | export function handleAsyncError<
T extends (...args: Parameters<T>) => Promise<void>,
>(asyncFunction: T) {
return (...args: Parameters<T>): void => {
(async (): Promise<void> => {
try {
await asyncFunction(...args);
} catch (error) {
const functionName = asyncFunction.name;
const isExpectedError = error instanceof Error;
const errorMessage = `Error in ${functionName}:\n${
isExpectedError ? error.message : "Unexpected error"
}`;
console.error(errorMessage);
}
})();
};
}
|