Created
May 14, 2023 13:13
-
-
Save christopherbauer/b0a297e11f72bfe1f875ab10d527b6b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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