xys-monitor
Version:
A project named xys-monitor
71 lines (51 loc) • 1.46 kB
JavaScript
import ReportConstructor from './js/report'
import CollectConstructor from './js/collect'
import { objectAssign } from './js/object'
import { handleManualMes } from './js/util'
import myConfig from './js/config'
class ErrorReport {
constructor () {
this.collect = ''
this.report = ''
this.options = ''
this.errTypeMap = myConfig.errTypeMap
this.extraErrorMsg = null
}
config (options = {}) {
this.options = objectAssign({}, this.options, options)
if (!this.report) {
this.report = new ReportConstructor(this)
}
if (!this.collect) {
this.collect = new CollectConstructor(this)
}
return this
}
throw (postdata) {
this.report.reportError(postdata)
return this
}
addPlugin (plugin, Frame) {
this.collect.addPlugin(plugin, Frame)
return this
}
setExtMsg (key, value) {
if (!this.extraErrorMsg) this.extraErrorMsg = {}
this.extraErrorMsg[key] = value
}
}
let exp = new ErrorReport()
//为了兼容老版本的错误上报
window._setErrPageId = function (pageId) {
exp.config({
pageId
})
return exp
}
export function $throw (args) {
return exp.throw(handleManualMes(args))
}
export function config (args) {
return exp.config(args)
}
export default exp