fix: 错误处理函数中oakErr交由业务自己判断

This commit is contained in:
Pan Qiancheng 2025-11-11 10:37:39 +08:00
parent d19cdec336
commit 9bb033a96b
4 changed files with 5 additions and 13 deletions

View File

@ -41,15 +41,11 @@ class AppLoader extends types_1.AppLoader {
*/
async publishInternalError(type, message, err) {
const errorToPublish = (0, lodash_1.cloneDeep)(err);
let oakException;
if (errorToPublish instanceof types_1.OakException) {
oakException = errorToPublish;
}
await Promise.all(this.internalErrorHandlers.map((handler) => {
return new Promise(async (resolve) => {
try {
const ctx = await this.makeContext();
handler(ctx, type, message, errorToPublish, oakException);
handler(ctx, type, message, errorToPublish);
}
catch (e) {
console.error('执行internalErrorHandler时出错', e);

View File

@ -1,6 +1,6 @@
import { BaseEntityDict } from "oak-domain";
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
import { EntityDict, OakException } from "oak-domain/lib/types";
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, oakException?: OakException<ED>) => Promise<void>;
export type InternalErrorHandler<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = (ctx: Cxt, type: InternalErrorType, message: string, err: Error) => Promise<void>;
export type ExceptionPublisher = (type: string, message: string, err: any) => Promise<void>;

View File

@ -49,16 +49,12 @@ export class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends Backe
*/
private async publishInternalError(type: InternalErrorType, message: string, err: any) {
const errorToPublish = cloneDeep(err);
let oakException: OakException<ED> | undefined;
if (errorToPublish instanceof OakException) {
oakException = errorToPublish;
}
await Promise.all(this.internalErrorHandlers.map(
(handler) => {
return new Promise<void>(async (resolve) => {
try {
const ctx = await this.makeContext();
handler(ctx, type, message, errorToPublish, oakException);
handler(ctx, type, message, errorToPublish);
} catch (e) {
console.error('执行internalErrorHandler时出错', e);
} finally {

View File

@ -3,5 +3,5 @@ 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, oakException?: OakException<ED>, ) => Promise<void>;
export type InternalErrorHandler<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> = (ctx: Cxt, type: InternalErrorType, message:string, err: Error) => Promise<void>;
export type ExceptionPublisher = (type: string, message: string, err: any) => Promise<void>;