1.0.6 • Published 4 years ago

custom-error-report v1.0.6

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

前端程序异常上报方法类

功能点

  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文件

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago