Files
Socket/public/static/handle/js/error-report.js
T
testadmin 817e262140 fix: frontend error reporting route - bypass auth middleware
- Create handle/controller/Log.php (no auth) for dealer error reports
- Update error-report.js URL: /index/log_report → /log/report
- index app already has Log controller at /log/report
2026-05-14 11:37:58 +08:00

48 lines
1.4 KiB
JavaScript

(function() {
var reportUrl = '/log/report';
var queue = [];
var sending = false;
function send(data) {
if (queue.length >= 10) return;
data.source = 'handle';
data.time = new Date().toISOString();
data.url = location.href;
queue.push(data);
flush();
}
function flush() {
if (sending || queue.length === 0) return;
sending = true;
var item = queue.shift();
var xhr = new XMLHttpRequest();
xhr.open('POST', reportUrl);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onloadend = function() { sending = false; flush(); };
xhr.onerror = function() { sending = false; };
xhr.timeout = 3000;
xhr.send(JSON.stringify(item));
}
window.onerror = function(message, source, lineno, colno, error) {
send({
type: 'error',
message: String(message),
stack: error && error.stack ? error.stack.substring(0, 2000) : '',
file: source,
line: lineno,
col: colno
});
};
window.addEventListener('unhandledrejection', function(event) {
var reason = event.reason;
send({
type: 'unhandledrejection',
message: reason && reason.message ? reason.message : String(reason),
stack: reason && reason.stack ? reason.stack.substring(0, 2000) : ''
});
});
})();