report-error-client.js
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import config from 'config';
const stringify = function(list) {
let data = [];
for (let i = 0; i < list.length; i++) {
let obj = list[i];
let params = [];
for (let prop in obj) {
if (obj.hasOwnProperty(prop)) {
params.push(prop + '::' + obj[prop]);
}
}
data.push(params.join('$$'));
}
return data.join('**');
};
const report = function(data) {
const str = stringify([data]);
if (!str) {
return;
}
const imgElem = new Image();
imgElem.src = config.reportUrl + '?s=yoho-app-web&l=' + str + '&t=' + (new Date()).getTime();
};
export default context => {
return (err) => {
if (process.env.NODE_ENV === 'production') {
setTimeout(() => {
try {
report({
tp: 'err',
msg: err.message,
sc: 'cdn.yoho.cn',
ln: 0,
cn: 0,
pt: encodeURIComponent(location.href),
u: 0,
ud: 0,
rid: 0,
st: JSON.stringify(err && err.stack),
r: context.route
});
} catch (error) {
console.log(error);
}
}, 0);
} else {
console.log(err);
}
};
};