Skip to content

Instantly share code, notes, and snippets.

@christopherbauer
Created May 14, 2023 13:13
Show Gist options
  • Save christopherbauer/b0a297e11f72bfe1f875ab10d527b6b8 to your computer and use it in GitHub Desktop.
Save christopherbauer/b0a297e11f72bfe1f875ab10d527b6b8 to your computer and use it in GitHub Desktop.
import logger from "../logger";
export const Graceful = (errorMessage: string) => {
return function captural(
originalMethod: Function,
_context: ClassMethodDecoratorContext
) {
function ReplacementMethod(this: any, ...args: any[]) {
try {
const result = originalMethod.call(this, ...args);
return result;
} catch (err) {
logger.error(err as Error);
return errorMessage;
}
}
return ReplacementMethod;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment