Skip to content

Commit

Permalink
feat: add user conf report url
Browse files Browse the repository at this point in the history
  • Loading branch information
MriLiuJY committed Jul 5, 2019
1 parent 1f283c0 commit 9a4f8ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@ import Wrap from "./wrap";
export const getServerError = function() {};

// ajaxError
export const ajaxError = function(err) {
export const ajaxError = function(err, config) {
// 处理err 上报
if (err.type === "ajaxLoad" && err.detail.status > 300) {
let data = new Wrap()._getErrorMessage(err);
ajax.post("/monitor", data, function() {},
ajax.post(config.url, data, function() {},
function(error) {
console.log(error);
});
}
}

// js 内部运行错误
export const getError = function(err) {
export const getError = function(err, config) {
// 可以被取消的是js抛出的错误
if (err.cancelable) {
getJsError(err);
getJsError(err, config);
} else {
geetResourceError(err);
geetResourceError(err, config);
}
}

// js 抛出的错误
const getJsError = function(err) {
const getJsError = function(err, config) {
let data = new Wrap()._getErrorMessage(err);
ajax.post("/monitor", data,
ajax.post(config.url, data,
function() {},
function(error) {
console.log(error);
});
}

// 资源加载错误
const geetResourceError = function (err) {
const geetResourceError = function (err, config) {
let data = ajax.getWraper(err, Wrap, true);
ajax.post("/monitor", data,
ajax.post(config.url, data,
function() {},
function(error) {
console.log(error);
Expand Down
27 changes: 18 additions & 9 deletions src/initMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ function InitMonitor(userConfig) {

InitMonitor.prototype = {
_initListenJS: function() {
const self = this;
// 监听全局下的error事件
window.addEventListener("error", function(err) {
getError(err);
if (err.filename.indexOf('monitor') > -1 || process.env.NODE_ENV === 'development') {
return;
} else {
getError(err, self._config);
}
}, true);

// 监听全局下的 Promise 错误
window.addEventListener("unhandledrejection", function(err){
console.log(err);
getError(err);
getError(err, self._config);
return true;
});
},
Expand Down Expand Up @@ -62,19 +66,24 @@ InitMonitor.prototype = {
self._startLintenAjax();
},
_startLintenAjax() {
// ajax error
window.addEventListener("error", function(err) {
ajaxError(err);
});
const self = this;

// ajax timeout
window.addEventListener("ajaxTimeout", function(err) {
ajaxError(err);
if (err.detail.responseURL.indexOf(self._config.url) > -1) {
return;
} else {
ajaxError(err, self._config);
}
});

// ajax load error
window.addEventListener("ajaxLoad", function(err) {
ajaxError(err);
if (err.detail.responseURL.indexOf(self._config.url) > -1) {
return;
} else {
ajaxError(err, self._config);
}
});
},
_send: function () {},
Expand Down

0 comments on commit 9a4f8ef

Please sign in to comment.