Skip to content

Commit

Permalink
feat: change get Wraper data
Browse files Browse the repository at this point in the history
  • Loading branch information
MriLiuJY committed Jun 27, 2019
1 parent 53cfdaf commit 8a3f2a3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1>Monitor testPage</h1>

initMonitor(config);
</script>
<script defer src="https://js.fundebug.cn/fundebug.1.8.2.min.js"
apikey="c57c87db91d85b9044db147237fba16d8273678123b2f1ca3d1f96f4d2e5f36f"></script>
<!-- <script defer src="https://js.fundebug.cn/fundebug.1.8.2.min.js"
apikey="c57c87db91d85b9044db147237fba16d8273678123b2f1ca3d1f96f4d2e5f36f"></script> -->
</body>
</html>
20 changes: 1 addition & 19 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,7 @@ const ajax = (function() {
getWraper: function(err, Wrap, resource) {
let wrap = new Wrap();
let data = wrap._geWrap();
wrap._getIP(function(ip) {
data.ip = ip;
});
if (err.type === "ajaxLoad") {
data.responseURL = err.detail.responseURL;
data.status = err.detail.status;
data.statusText = err.detail.statusText;
data.type = "ajaxLoad";
} else if (err.type === "error") {
data.message = err.message;
data.line = err.lineno;
data.filename = err.filename;
data.type = "error";
} else if (resource) {
data.src = err.target.src;
data.type = "resource";
}
console.log(err);
return data

},
}
})();
Expand Down
19 changes: 8 additions & 11 deletions src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export const getServerError = function() {};
export const ajaxError = function(err) {
// 处理err 上报
if (err.type === "ajaxLoad" && err.detail.status > 300) {
let data = ajax.getWraper(err, Wrap)
ajax.post("/monitor", data,
function() {},
let data = new Wrap()._getErrorMessage(err);
ajax.post("/monitor", data, function() {},
function(error) {
console.log(error);
});
Expand All @@ -36,14 +35,12 @@ export const getError = function(err) {

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

// 资源加载错误
Expand Down
8 changes: 0 additions & 8 deletions src/stateChange.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ Wrap.prototype = {
ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
};
},
// 处理错误信息
_getErrorMessage: function(err, resource) {
const self = this;
let data = self._geWrap();
self._getIP(function(ip) {
data.ip = ip;
});
if (err.type === "ajaxLoad") {
data.responseURL = err.detail.responseURL;
data.status = err.detail.status;
data.statusText = err.detail.statusText;
data.type = "ajaxLoad";
} else if (err.type === "error") {
data.message = err.message;
data.line = err.lineno;
data.filename = err.filename;
data.type = "error";
} else if (resource) {
data.src = err.target.src;
data.type = "resource";
}

console.log(data);
return data
},
}

module.exports = Wrap;

0 comments on commit 8a3f2a3

Please sign in to comment.