From 22e48d7db1c8c5043b0cbad3517fa5faa6684dc5 Mon Sep 17 00:00:00 2001 From: yuantao Date: Mon, 30 Mar 2026 18:21:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=5FsendErrorToWebhook?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E7=9A=84webhookUrl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index bb75903..197ea09 100644 --- a/src/index.js +++ b/src/index.js @@ -744,16 +744,18 @@ class ErrorMonitor { * @private */ async _sendErrorToWebhook(errorInfo, retryCount = 0, forceSend = false) { - // 环境检查:只在生产环境下发送错误信息 - if (!forceSend && !this._isProduction() && !this.config?.forceEnable) { - console.info('非生产环境,错误信息不上报到webhook:', errorInfo.type) - return - } - const webhookUrl = import.meta.env.VITE_WEBHOOK - if (!webhookUrl) { - console.error('未配置webhook地址,无法发送错误信息') - return - } + // 环境检查:只在生产环境下发送错误信息 + if (!forceSend && !this._isProduction() && !this.config?.forceEnable) { + console.info('非生产环境,错误信息不上报到webhook:', errorInfo.type) + return + } + + // 优先使用配置中的 webhookUrl,否则使用环境变量 + const webhookUrl = this.config?.webhookUrl || import.meta.env.VITE_WEBHOOK + if (!webhookUrl) { + console.error('未配置webhook地址,无法发送错误信息') + return + } try { // 格式化错误信息 const message = this._formatErrorMessage(errorInfo)