diff --git a/api/request.js b/api/request.js index 3174fdc..2207b10 100644 --- a/api/request.js +++ b/api/request.js @@ -31,6 +31,10 @@ http.interceptors.response.use(response => { if (response.statusCode == 401 || response.data.code == 401) { } + if (response.data.code !== 1 || response.data.code !== 200) { + tool.reportError('network', response.data) + } + if (response.statusCode == 200) { return Promise.resolve(response) } else { diff --git a/common/utils/tool.js b/common/utils/tool.js index 75206a2..07ffa27 100644 --- a/common/utils/tool.js +++ b/common/utils/tool.js @@ -551,9 +551,9 @@ class Tool { * @param {Object} [context] 错误上下文信息 * @param {boolean} [forceSend=false] 强制发送(忽略环境检查) */ - reportError(error, context = {}, forceSend = false) { + reportError(type = 'manual', error, context = {}, forceSend = false) { const errorInfo = { - type: 'manual', + type, error: error instanceof Error ? error.message : error, stack: error instanceof Error ? error.stack : null, context, @@ -562,6 +562,9 @@ class Tool { userAgent: this._getUserAgent(), page: getCurrentPageName(), } + this.errorStats.total++ + this.errorStats.miniProgram++ + this.errorStats.lastErrorTime = errorInfo.timestamp if (forceSend) { // 强制发送