zoukankan      html  css  js  c++  java
  • Ionic2中腾讯Bugly异常捕获以及上报

    Ionic2混合开发,入坑系列:Ionic2中腾讯Bugly异常捕获以及上报

    1、Ionic2中处理全局异常,直接继承IonicErrorHandler即可,代码如下

    import { IonicErrorHandler } from 'ionic-angular';
    import { Bugly } from './../plugins/TX-bugly.plugin'
    import { Config } from './../config/config'
    /**
     * Ionic2全局异常捕获
     */
    export class GlobalIonicErrorHandler extends IonicErrorHandler {
    
    
        /**
         * 异常处理
         * @param err 异常信息
         */
        handleError(err: any): void {
            let _message = err._nativeError || err.message || err._nativeError.message || "";
            let _stack = err._nativeError || err.stack || err._nativeError.stack;
            let params: any = { message: _message, stack: _stack, platform: Config.APP_PLATFORM };
            console.log("错误:" + _message);
            console.log("堆栈:" + _stack);
            Bugly.buglySend(JSON.stringify(params));
        }
    }

    2、在AppModule.ts中将自定义的异常扩类添加到providers中

    import { NgModule, ErrorHandler } from '@angular/core';
    import { IonicApp, IonicModule } from 'ionic-angular';
    import { MyApp } from './app.component';
    import './rxjs-extensions';
    import { GlobalIonicErrorHandler } from './global-error-handler-ionic.extend'

    @NgModule({ declarations: [ MyApp ], bootstrap: [IonicApp], entryComponents: [ MyApp ], imports: [ IonicModule.forRoot(MyApp, { tabsHideOnSubPages: true, iconMode: 'ios', modalEnter: 'modal-slide-in', modalLeave: 'modal-slide-out', tabsPlacement: 'bottom', pageTransition: 'ios' }), ComponentBusinessModule ], providers: [ { provide: ErrorHandler, useClass: GlobalIonicErrorHandler }] }) export class AppModule { }
  • 相关阅读:
    js对象数组(JSON) 根据某个共同字段 分组
    ajax如何处理服务器返回的三种数据类型
    JavaScript中常见排序算法详解
    《JavaScript语言精粹》读书笔记——给类型增加方法一节的疑问
    前端常见跨域解决方案(全)
    ACE模板的布局简介
    ES6学习笔记---对象的扩展
    偏振
    欧拉赞词
    狄拉克δ函数的导数
  • 原文地址:https://www.cnblogs.com/xhh-lite/p/6485126.html
Copyright © 2011-2022 走看看