Skip to content

Instantly share code, notes, and snippets.

@tkafka
Created January 5, 2023 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkafka/bc6157c8facd012a6d7937a083c01829 to your computer and use it in GitHub Desktop.
Save tkafka/bc6157c8facd012a6d7937a083c01829 to your computer and use it in GitHub Desktop.
export function wrapInErrorHandler<Func extends (...args: any[]) => any>(func: Func): (...args: InferArguments<Func>) => InferReturn<Func> {
return function (...args: InferArguments<Func>) {
try {
return func.apply(null, args);
} catch (err: any) {
if (err instanceof LoggedError) {
throw err;
}
post({ your- error - object});
throw new LoggedError(err);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment