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
| window.onerror = (message, source, lineno, colno, error) => { if (lineno != lineno1 && colno1 != lineno && message != message1) { HttpReq.Ins.reqDotting(error, { type: `5`, content: `捕获到全局错误:来源: ${source},行号: ${lineno},列号: ${colno}`, additional: `错误对象: ${error}` }); } lineno1 = lineno; colno1 = colno; message1 = message; return true; };
window.addEventListener("unhandledrejection", (event) => { let errorInfo = { message: "", stack: "", };
if (event.reason instanceof Error) { errorInfo.message = event.reason.message; errorInfo.stack = event.reason.stack; } else { errorInfo.message = event.reason.toString(); } const errorInfoString = JSON.stringify(errorInfo); HttpReq.Ins.reqDotting(ClientDottingName.error, { type: `3`, content: `未处理的 Promise 异常`, additional: `${errorInfoString}` }); });
window.addEventListener("error", (event) => { const target = event.target as HTMLElement; if (target && (target.tagName === "IMG" || target.tagName === "SCRIPT" || target.tagName === "LINK")) { HttpReq.Ins.reqDotting(error, { type: `4`, content: `资源加载失败:`, additional: `${target.getAttribute("src") || target.getAttribute("href")}` }); } }, true);
|