提交 c820842e 编写于 作者: DCloud_JSON's avatar DCloud_JSON

新增 客户端错误日志收集功能

上级 71ecac6a
......@@ -271,4 +271,30 @@ export default {
showCancel: false
});
},
async reportError(error){
// 上报错误
const dbJQL = uniCloud.databaseForJQL()
let content = {
stack: error.stack,
message: error.message,
code: error.code
}
content = JSON.stringify(content)
const content_md5 = md5(error.message)
// 查询是否已经上报过
let res = await dbJQL.collection('uni-im-error-log').where({
content_md5
}).get()
if(res.data.length === 0){
res = await dbJQL.collection('uni-im-error-log').add({
content,
content_md5
})
}else{
res = await dbJQL.collection('uni-im-error-log').doc(res.data[0]._id).update({
count: (res.data[0]?.count || 1) + 1
})
}
console.warn('【bug已上报】uni-im-sdk error has reported',res,{error})
}
}
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType": "object",
"required": [],
"permission": {
"read": false,
"create": "auth.uid != null",
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id": {
"bsonType": "string",
"description": "反馈用户ID",
"foreignKey": "uni-id-users._id",
"forceDefaultValue": {
"$env": "uid"
}
},
"create_time": {
"bsonType": "timestamp",
"forceDefaultValue": {
"$env": "now"
}
},
"content": {
"bsonType": "string",
"title": "内容"
},
"count": {
"bsonType": "int",
"description": "反馈次数"
},
"content_md5": {
"bsonType": "string",
"description": "内容MD5,用于防止重复插入重复的信息"
},
"is_fixed": {
"bsonType": "bool",
"description": "是否已修复",
"forceDefaultValue": false
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册