Encountering an issue in my error handler with the following message:
Uncaught TypeError: Converting circular structure to JSON
.
I suspect that there might be an additional exception thrown within the JSON.stringify
call leading to this error. It's puzzling as to how err_msg
, err_url
, or err_line
could be self-referential in this context.
Is there a way to prevent circular references in this code? Any insights on the root cause of this error?
window.onerror = function myErrorHandler(err_msg, err_url, err_line) {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/log-receiver", true);
xhr.setRequestHeader('X-Csrftoken', document.getElementsByName("csrfmiddlewaretoken")[0].value);
xhr.setRequestHeader('Content-Type', "application/json;charset=UTF-8");
xhr.send(JSON.stringify({
message: err_msg,
url: err_url,
line: err_line,
level: 'ERROR'
}));
return false;
}