From c820842ef2d980af627f438de2ccf9a49a4c1627 Mon Sep 17 00:00:00 2001 From: linju Date: Wed, 13 Nov 2024 21:06:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=E6=94=B6=E9=9B=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/utils/index.js | 26 ++++++++++ .../database/uni-im-error-log.schema.json | 47 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 uniCloud/database/uni-im-error-log.schema.json diff --git a/sdk/utils/index.js b/sdk/utils/index.js index b502196..64130f5 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 0000000..cc6f10b --- /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 -- GitLab