feat: 从requireSth加载ExceptionHandler
This commit is contained in:
parent
9bb033a96b
commit
6bf221da5f
|
|
@ -19,6 +19,7 @@ export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt exten
|
|||
private watcherTimerId?;
|
||||
private scheduledJobs;
|
||||
private internalErrorHandlers;
|
||||
regAllExceptionHandler(): void;
|
||||
/**
|
||||
* 注册一个内部错误处理器
|
||||
* @param handler 内部错误处理器
|
||||
|
|
|
|||
|
|
@ -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 内部错误处理器
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue