From c40170db5d8d72e2df0fb3bd0b138f3bf156f6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E5=AE=9D=E5=AE=9D?= <109729945+initialencounter@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:33:09 +0800 Subject: [PATCH] feat(onebot11): Improve error handling in JSON parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 发生错误直接被 catch 掉了,没有提示,[使用docker启动后,请求被重置](https://github.com/NapNeko/NapCat-Docker/issues/8) --- src/onebot11/config.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/onebot11/config.ts b/src/onebot11/config.ts index 2457724a6..0ba3457e4 100644 --- a/src/onebot11/config.ts +++ b/src/onebot11/config.ts @@ -67,6 +67,11 @@ class Config implements OB11Config { Object.assign(this, jsonData); // eslint-disable-next-line } catch (e) { + if (e instanceof SyntaxError) { + console.error(`配置文件 ${ob11ConfigPath} 格式错误,请检查配置文件:`, e.message); + }else{ + console.error(`读取配置文件 ${ob11ConfigPath} 时发生错误:`, e.message); + } } return this; }