From df8426d1029ab098b4041caaa25d5c0ad790eb9f Mon Sep 17 00:00:00 2001 From: QCQCQC <1220204124@zust.edu.cn> Date: Thu, 16 Oct 2025 11:18:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86require=20errors.js?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/server/start.js | 8 +++++++- src/server/start.ts | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/server/start.js b/lib/server/start.js index 940c38b..51e772a 100644 --- a/lib/server/start.js +++ b/lib/server/start.js @@ -39,7 +39,13 @@ function concat(...paths) { }); } async function startup(path, connector, omitWatchers, omitTimers, routine) { - const errorHandler = require((0, path_1.join)(path, 'lib', 'configuration', 'errors')).default; + let errorHandler = undefined; + try { + errorHandler = require((0, path_1.join)(path, 'lib', 'configuration', 'errors')).default; + } + catch (err) { + // 不存在errors配置 + } const serverConfiguration = require((0, path_1.join)(path, 'lib', 'configuration', 'server')).default; // 拿到package.json,用作项目的唯一标识,否则无法区分不同项目的Redis+socketIO连接 const packageJson = require((0, path_1.join)(path, 'package.json')); diff --git a/src/server/start.ts b/src/server/start.ts index da2fbb7..80485f8 100644 --- a/src/server/start.ts +++ b/src/server/start.ts @@ -57,12 +57,18 @@ export async function startup) => Promise, ): Promise<(() => Promise) | any> { - const errorHandler: ErrorHandler = require(join( - path, - 'lib', - 'configuration', - 'errors' - )).default; + let errorHandler: ErrorHandler | undefined = undefined; + + try { + errorHandler = require(join( + path, + 'lib', + 'configuration', + 'errors' + )).default; + } catch (err) { + // 不存在errors配置 + } const serverConfiguration: ServerConfiguration = require(join( path, @@ -218,7 +224,7 @@ export async function startup { if (props.level === "error") { appLoader.execRoutine(async (ctx) => { - await errorHandler( props.caller, props.args, ctx); + await errorHandler(props.caller, props.args, ctx); }).catch((err) => { console.warn('执行全局错误处理失败:', err); });