Skip to content

Commit

Permalink
feat: add js running error catch
Browse files Browse the repository at this point in the history
  • Loading branch information
MriLiuJY committed Jun 25, 2019
1 parent b61e367 commit c4db726
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions createError.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ajaxTimeout.onclick = function () {
// js 执行错误
var jsRunningerror = document.getElementsByClassName("js-running-error")[0];
jsRunningerror.onclick = function () {
jsRunningerrorssss;
}


Expand Down
13 changes: 10 additions & 3 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ const ajax = (function() {
wrap._getIP(function(ip) {
data.ip = ip;
});
data.responseURL = err.detail.responseURL;
data.status = err.detail.status;
data.statusText = err.detail.statusText;
if (err.type === "ajaxLoad") {
data.responseURL = err.detail.responseURL;
data.status = err.detail.status;
data.statusText = err.detail.statusText;
} else if (err.type === "error") {
data.message = err.message;
data.line = err.lineno;
data.filename = err.filename;
}
console.log(err);
return data
},
}
Expand Down
7 changes: 7 additions & 0 deletions src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ export const getError = function(err) {
const getJsError = function(err) {
console.log(err);
// 处理err 上报
let data = ajax.getWraper(err, Wrap)
ajax.post("/monitor", data,
function() {},
function(error) {
console.log(error);
});
}

// 资源加载错误
const geetResourceError = function (err) {
console.log(err);
console.log("geetResourceError");
}
6 changes: 6 additions & 0 deletions src/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ Wrap.prototype = {
// languages
data.language = navigator.language;

// url
data.url = window.location.href;

// time
data.time = (new Date()).getTime();

return data;
},
// webrtc 获取 IP
Expand Down

0 comments on commit c4db726

Please sign in to comment.