新增 API请求错误自动上报功能

This commit is contained in:
yuantao
2025-12-01 16:10:42 +08:00
parent ba839a1e47
commit 3fbb7294fb
2 changed files with 9 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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) {
// 强制发送