fix(sdk): handle api error response code correctly and improve missing token hints

- Fixed an issue where the request function silently resolved on HTTP 200 even when the JSON body contained an API error (e.g. code 401). Now explicitly throws when code != 200.
- Improved error messages when OpenAPI or Notify tokens are completely missing, explicitly instructing the user to configure them in the panel.
This commit is contained in:
duorameng
2026-05-27 17:46:03 +08:00
parent 20d0ab54d1
commit d9f47daf29
5 changed files with 27 additions and 9 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ function notify(title, text, channelId) {
const missing = [];
if (!token) missing.push("BHPKG_NOTIFY_TOKEN");
if (!channel) missing.push("BHPKG_NOTIFY_CHANNEL");
throw new Error(`缺少必要的环境变量以使用 notify 函数: ${missing.join(", ")}。请在白虎面板的任务设置中配置这些 Key。`);
throw new Error(`没有正确配置或缺少 ${missing.join(" ")} 环境变量以使用 notify 函数。请在白虎面板的任务设置中配置这些 Key。`);
}
const notifyUrl = process.env.BHPKG_NOTIFY_URL || 'http://localhost:8052/api/v1/notify/send';