From 6ad59a6ae7ffa480b605b1538fa5c50a1e904135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=81=E6=B6=9B?= Date: Mon, 1 Dec 2025 22:40:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E5=92=8C=E7=89=88=E6=9C=AC=E5=8F=B7=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 16 +++++---------- src/ErrorMonitor.js | 47 +++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 72d74a4..4a80f44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uniapp-error-monitor", - "version": "1.0.0", + "version": "1.0.1", "description": "专门为UniApp环境设计的错误监控和上报工具,支持全局错误捕获、Promise错误捕获、网络错误捕获等", "main": "dist/index.js", "module": "dist/index.esm.js", @@ -28,12 +28,9 @@ "license": "MIT", "repository": { "type": "git", - "url": "https://github.com/iflow-dev/uniapp-error-monitor.git" + "url": "hhttps://git.pandorastudio.cn/product/uniapp-error-monitor.git" }, - "bugs": { - "url": "https://github.com/iflow-dev/uniapp-error-monitor/issues" - }, - "homepage": "https://github.com/iflow-dev/uniapp-error-monitor#readme", + "homepage": "https://git.pandorastudio.cn", "engines": { "node": ">=14.0.0", "npm": ">=6.0.0" @@ -42,11 +39,9 @@ "build": "rollup -c", "dev": "rollup -c -w", "clean": "rimraf dist", - "test": "jest", - "test:watch": "jest --watch", "lint": "eslint src/**/*.js", "lint:fix": "eslint src/**/*.js --fix", - "prepublishOnly": "npm run clean && npm run build && npm test" + "prepublishOnly": "npm run clean && npm run build" }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.0", @@ -55,7 +50,6 @@ "rollup": "^3.0.0", "rollup-plugin-terser": "^7.0.0", "typescript": "^5.0.0", - "jest": "^29.0.0", "eslint": "^8.0.0", "rimraf": "^5.0.0" }, @@ -74,4 +68,4 @@ "iOS >= 10", "Android >= 6" ] -} \ No newline at end of file +} diff --git a/src/ErrorMonitor.js b/src/ErrorMonitor.js index a36dcb4..8186664 100644 --- a/src/ErrorMonitor.js +++ b/src/ErrorMonitor.js @@ -248,23 +248,25 @@ class ErrorMonitor { _setupMiniProgramErrorHandlers() { if (typeof uni !== 'undefined') { // 监听小程序错误事件 - uni.onError && uni.onError(error => { - this._handleMiniProgramError({ - type: 'miniProgram', - error, - timestamp: Date.now(), + uni.onError && + uni.onError(error => { + this._handleMiniProgramError({ + type: 'miniProgram', + error, + timestamp: Date.now(), + }) }) - }) // 监听小程序页面错误 - uni.onPageNotFound && uni.onPageNotFound(result => { - this._handleMiniProgramError({ - type: 'pageNotFound', - path: result.path, - query: result.query, - timestamp: Date.now(), + uni.onPageNotFound && + uni.onPageNotFound(result => { + this._handleMiniProgramError({ + type: 'pageNotFound', + path: result.path, + query: result.query, + timestamp: Date.now(), + }) }) - }) // 监听小程序网络请求错误 const originalRequest = uni.request @@ -389,7 +391,7 @@ class ErrorMonitor { } else { await this._sendToWebhook(errorInfo) } - + console.log('[ErrorMonitor] 错误信息已处理') } catch (error) { console.error('[ErrorMonitor] 发送错误信息失败:', error) @@ -408,9 +410,7 @@ class ErrorMonitor { } // 格式化错误信息 - const message = this.config?.customFormatter - ? this.config.customFormatter(errorInfo) - : this._formatErrorMessage(errorInfo) + const message = this.config?.customFormatter ? this.config.customFormatter(errorInfo) : this._formatErrorMessage(errorInfo) // 使用uni.request发送POST请求(适配uniapp环境) await new Promise((resolve, reject) => { @@ -439,10 +439,11 @@ class ErrorMonitor { */ _formatErrorMessage(errorInfo) { const timestamp = new Date(errorInfo.timestamp).toLocaleString('zh-CN') + const systemInfo = uni.getSystemInfoSync?.() let message = `🚨 JavaScript错误报告\n` - message += `📦 项目: ${this.projectInfo.name}\n` - message += `🏷️ 版本: ${this.projectInfo.version}\n` + message += `📦 项目: ${systemInfo.appName || this.projectInfo.name}\n` + message += `🏷️ 版本: ${systemInfo.appVersion || this.projectInfo.version}\n` message += `⏰ 时间: ${timestamp}\n` message += `📱 页面: ${errorInfo.page || '未知页面'}\n` message += `🌐 链接: ${errorInfo.url || '未知链接'}\n\n` @@ -644,12 +645,12 @@ class ErrorMonitor { * @private */ _getMode() { - if (typeof import !== 'undefined' && import.meta?.env?.MODE) { - try { + try { + if (import.meta?.env?.MODE) { return import.meta.env.MODE - } catch (error) { - // 忽略访问错误 } + } catch (error) { + // 忽略访问错误 } return 'unknown' }