feat: 修改异常处理器的类型,添加name

This commit is contained in:
Pan Qiancheng 2025-11-11 11:40:26 +08:00
parent 6bf221da5f
commit e646236e8d
4 changed files with 20 additions and 4 deletions

View File

@ -43,6 +43,10 @@ class AppLoader extends types_1.AppLoader {
* @param handler 内部错误处理器
*/
registerInternalErrorHandler(handler) {
// 检查有没有名称重复
if (this.internalErrorHandlers.find(h => h.name === handler.name)) {
throw new Error(`内部错误处理器名称重复: ${handler.name}`);
}
this.internalErrorHandlers.push(handler);
}
/**
@ -54,7 +58,8 @@ class AppLoader extends types_1.AppLoader {
return new Promise(async (resolve) => {
try {
const ctx = await this.makeContext();
handler(ctx, type, message, errorToPublish);
console.log(`调用internalErrorHandler【${handler.name}】处理内部错误事件`);
handler.handle(ctx, type, message, errorToPublish);
}
catch (e) {
console.error('执行internalErrorHandler时出错', e);

View File

@ -2,5 +2,8 @@ import { BaseEntityDict } from "oak-domain";
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
import { EntityDict } from "oak-domain/lib/types";
export type InternalErrorType = 'aspect' | 'trigger' | 'watcher' | 'timer' | 'checkpoint';
export type InternalErrorHandler<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = (ctx: Cxt, type: InternalErrorType, message: string, err: Error) => Promise<void>;
export type InternalErrorHandler<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = {
name: string;
handle: (ctx: Cxt, type: InternalErrorType, message: string, err: Error) => Promise<void>;
};
export type ExceptionPublisher = (type: string, message: string, err: any) => Promise<void>;

View File

@ -52,6 +52,10 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
* @param handler
*/
public registerInternalErrorHandler(handler: InternalErrorHandler<ED, Cxt>) {
// 检查有没有名称重复
if (this.internalErrorHandlers.find(h => h.name === handler.name)) {
throw new Error(`内部错误处理器名称重复: ${handler.name}`);
}
this.internalErrorHandlers.push(handler);
}
@ -65,7 +69,8 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
return new Promise<void>(async (resolve) => {
try {
const ctx = await this.makeContext();
handler(ctx, type, message, errorToPublish);
console.log(`调用internalErrorHandler【${handler.name}】处理内部错误事件`);
handler.handle(ctx, type, message, errorToPublish);
} catch (e) {
console.error('执行internalErrorHandler时出错', e);
} finally {

View File

@ -3,5 +3,8 @@ import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
import { EntityDict, OakException } from "oak-domain/lib/types";
export type InternalErrorType = 'aspect' | 'trigger' | 'watcher' | 'timer' | 'checkpoint'
export type InternalErrorHandler<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = (ctx: Cxt, type: InternalErrorType, message:string, err: Error) => Promise<void>;
export type InternalErrorHandler<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = {
name: string;
handle: (ctx: Cxt, type: InternalErrorType, message:string, err: Error) => Promise<void>;
}
export type ExceptionPublisher = (type: string, message: string, err: any) => Promise<void>;