ECat 小程序 SDK使用文档#
功能说明:
- 当前仅支持微信小程序
- 支持JsError、UnhandledRejection、PageNotFoundError、MemoryWarning的上传
- 支持自定义异常上传
一、接入步骤#
1.1 SDK文件说明#
- ECat.min.js: SDK文件
1.2 在微信开发者工具中集成#
-
将SDK文件复制到工程目录下(列如:utils目录)
-
在app.js导入SDK并初始化(也可在其他函数中初始化):
import {ECat} from './utils/ECat.min';
App({
onLaunch() {
//初始化参数中,appId为必填参数
ECat.init('平台分配的appId', {
appVersion: '1.0.0',
appChannel: 'Channel',
userId: '123'
});
},
globalData: {
userInfo: null
}
})
1.3 接入测试#
在初始化后,运行小程序,手动抛出一个jsError
throw new Error('测试JavaScript运行时错误');
然后在ECat平台->控制台->异常列表中查看数据。
1.4 域名配置#
请在对应平台的合法域名配置页面添加SDK使用的域名:
二、API说明#
ECat类#
该类提供ECat API接口
// 异常捕获SDK API层
import { CrashSDKImpl } from './core/CrashSDKImpl';
/**
* 异常捕获SDK核心类(API层)
*/
var ECat = /** @class */ (function () {
function ECat() {
}
/**
* 初始化SDK
*/
ECat.init = function (appId, config) {
if (config === void 0) { config = {}; }
if (!this.impl) {
this.impl = new CrashSDKImpl();
}
this.impl.init(appId, config);
};
/**
* 手动上报异常
*/
ECat.reportManualError = function (error) {
if (this.impl) {
this.impl.reportManualError(error);
}
};
/**
* 上报异常
* @param error 异常对象
*/
ECat.reportException = function (type, name, message, stack) {
if (this.impl) {
this.impl.reportException(type, name, message, stack);
}
};
/**
* 设置应用版本
* @param appVersion 应用版本
*/
ECat.setAppVersion = function (appVersion) {
if (this.impl) {
this.impl.setAppVersion(appVersion);
}
};
/**
* 设置用户ID
* @param userId 用户ID
*/
ECat.setUserId = function (userId) {
if (this.impl) {
this.impl.setUserId(userId);
}
};
/**
* 添加自定义键值对
* @param key 键名,长度需小于32字节
* @param value 值,长度需小于1024字节
*/
ECat.addCustomField = function (key, value) {
CrashSDKImpl.addCustomField(key, value);
};
/**
* 删除自定义键值对
* @param key 键名
*/
ECat.removeCustomField = function (key) {
CrashSDKImpl.removeCustomField(key);
};
/**
* 清空所有自定义键值对
*/
ECat.clearCustomFields = function () {
CrashSDKImpl.clearCustomFields();
};
/**
* 禁用SDK
*/
ECat.disable = function () {
if (this.impl) {
this.impl.disable();
}
};
ECat.impl = null;
return ECat;
}());
export { ECat };