Fixed errors thrown in CRON hook not caught (#8193)

This commit is contained in:
ian
2021-09-21 22:40:25 +08:00
committed by GitHub
parent b700f2fe73
commit d472e2c2b6

View File

@@ -173,7 +173,13 @@ function registerHooks(hooks: Extension[]) {
if (!cron || validate(cron) === false) {
logger.warn(`Couldn't register cron hook. Provided cron is invalid: ${cron}`);
} else {
schedule(cron, handler);
schedule(cron, async () => {
try {
await handler();
} catch (error: any) {
logger.error(error);
}
});
}
} else {
emitter.on(event, handler);