You've already forked template-MP
新增 API请求错误自动上报功能
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
// 强制发送
|
||||
|
||||
Reference in New Issue
Block a user