feat: 从requireSth加载ExceptionHandler

This commit is contained in:
Pan Qiancheng 2025-11-11 11:02:52 +08:00
parent 9bb033a96b
commit 6bf221da5f
3 changed files with 22 additions and 1 deletions

1
lib/AppLoader.d.ts vendored
View File

@ -19,6 +19,7 @@ export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt exten
private watcherTimerId?;
private scheduledJobs;
private internalErrorHandlers;
regAllExceptionHandler(): void;
/**
*
* @param handler

View File

@ -29,6 +29,15 @@ class AppLoader extends types_1.AppLoader {
watcherTimerId;
scheduledJobs = {};
internalErrorHandlers = new Array();
regAllExceptionHandler() {
const handlers = this.requireSth('lib/configuration/exception');
if (Array.isArray(handlers)) {
handlers.forEach((handler) => this.registerInternalErrorHandler(handler));
}
else {
console.warn('lib/configuration/exception必须默认导出一个处理器数组当前导出类型不正确将忽略此配置');
}
}
/**
* 注册一个内部错误处理器
* @param handler 内部错误处理器

View File

@ -36,6 +36,17 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
private scheduledJobs: Record<string, Job> = {};
private internalErrorHandlers = new Array<InternalErrorHandler<ED, Cxt>>();
public regAllExceptionHandler() {
const handlers = this.requireSth('lib/configuration/exception') as Array<InternalErrorHandler<ED, Cxt>> | InternalErrorHandler<ED, Cxt>;
if (Array.isArray(handlers)) {
handlers.forEach(
(handler) => this.registerInternalErrorHandler(handler)
);
} else {
console.warn('lib/configuration/exception必须默认导出一个处理器数组当前导出类型不正确将忽略此配置');
}
}
/**
*
* @param handler
@ -626,7 +637,7 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
await context.commit();
return result;
}
catch(e: any) {
catch (e: any) {
await context.rollback();
throw e;
}