Closed bianxiang closed 4 years ago
不太清楚你想要什么效果,一般throw就行,如果是错误过滤,有filter参数
就是上传指定的字符串,比如网络请求错误,把这条请求的路径参数和返回的状态码上传到bugly
试试putUserData方法
@crazecoder putUserData已经用过啦,用来标识的,我现在想自定义上传错误,这个putUserData不能再用了哦
目前是抓取flutter的异常,利用bugly提供的单独上报方法去做的,单独根据某个异常去上报不太好做,现在能想到的解决方法,就是手动去catch对应异常,然后throw一个带map的自定义Exception,但是总觉得不是太合适,不知道你有没有更好的想法
try{
throw "123";
}catch(e){
throw CustomException(message:e.toString(),map: {"test": "ceshi"});
}
使用方法类似这样,代码还没上传
flutter我也是刚学,您参考一下sentry,国外的,github有flutter版本,看看是怎么做的,这是我接入后的效果
try{ throw "123"; }catch(e){ throw CustomException(message:e.toString(),map: {"test": "ceshi"}); }
使用方法类似这样,代码还没上传
如果这样写,程序进了catch里面,不会崩溃吗?据我了解好像会吧,我现在是只想上传网络请求的报错,不影响程序运行哦
异步里是不会影响程序的,还是封装一下吧,类似这种
try {
throw "123";
} catch (e) {
FlutterBugly.throwException(message: e.toString(), data: {"test": "ceshi"});
}
如果没有其他好的方法,只能这样了
flutter我也是刚学,您参考一下sentry,国外的,github有flutter版本,看看是怎么做的,这是我接入后的效果
这个是我线上项目的日志,个人觉得还是需要去自定义exception,毕竟框架也不知道返回json的格式
FlutterBugly
噢噢 目前FlutterBugly.throwException(message: e.toString(), data: {"test": "ceshi"});这样写还没上传对吧
能否再简洁一点,还需要写个try catch
用FlutterBugly封装一下try throw catch?
static var sentry = SentryClient(dsn: "https://8433d1ae288343eaa64998888e3575ae@sentry.io/1729182");
sentry.captureException(exception: "接口报错==>${e.response.request.path},状态码:${e.response.statusCode},${e.response.data['Message']}");
类似这样使用
try catch 只是为了调试,实际情况,在遇到异常的时候直接throwException就可以了,例如dio里使用
await _dio.get<Map>(url).catchError((_error) {
if (CancelToken.isCancel(_error)) {
debugLog('Request canceled! ' + _error.message);
} else {
FlutterBugly.throwException(message: _error.toString(), data: {"test": "ceshi"});
}
return null;
});
代码已提交到beta分支,你可以引用beta分支试试
d3d1ab9213b97b4191ceabb5b4b6ddc068550509 把直接上报方法开放出来了,你或者可以直接用upload
你可以的,完美!😄
如何自定义上传错误?