包详细信息

custom-error-report

huangwenming4ISC1.0.6

Capture exceptions in front-end programs and upload the exceptions to the specified server.

error, exceptions, upload

自述文件

前端程序异常上报方法类

功能点

  1. 支持window.onerror和vue.config.errorHandler的错误信息捕捉;
  2. 将错误信息格式统一,然后通过jsonp格式进行上报。

错误信息的格式如下

    let errorObj = {
        project: '', // 页面所属项目
        message: '',
        script: '',
        lineNo: '',
        columnNo: '',
        stack: '',
    };

使用方法

  npm i --save custom-error-report
    import ErrorReport from 'custom-error-report';

    let errorReport = new ErrorReport({
        supportType: 'vue', // 支持vue项目
        vueIns: Vue, // 传入vue对象
        project: 'collection', // 页面所属的项目
        collectAddress: 'http://localhost:8585/middleware/errorMsg/', // 接受错误信息的服务地址(需要结合自己的项目配置)
        sourceMapAddress: 'http://localhost:8585/client/test-error/' // sourceMap的访问地址(需要结合自己的项目配置)
    });
    errorReport.enableCatchError();

    // react项目需要手动上报错误信息,错误信息包含在stack中
    componentDidCatch(error, errorInfo) {
        errorReport.sendStackErrorInfo({
            message: error.message,
            stack: error.stack
        });
    }
    // 支持直接上报自定义的错误内容(如API接口中的数据不是前端所需要的,需要进行上报收集)
    errorReport.sendErrorInfo({
        message: 'the data from xx api cannot meet FE need'
    });

示例

参考examples文件夹下的readme文件