diff --git a/sdk/utils/index.js b/sdk/utils/index.js index b5021965f9d62352a52b61c69b32c9745525f28e..64130f5f880a1a7daabc914047bb8a8b70a52de0 100644 --- a/sdk/utils/index.js +++ b/sdk/utils/index.js @@ -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}) + } } diff --git a/uniCloud/database/uni-im-error-log.schema.json b/uniCloud/database/uni-im-error-log.schema.json new file mode 100644 index 0000000000000000000000000000000000000000..cc6f10bf8c6ec76203e6c9c15e77a1f460b18eb3 --- /dev/null +++ b/uniCloud/database/uni-im-error-log.schema.json @@ -0,0 +1,47 @@ +// 文档教程: 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