Skip to content

Instantly share code, notes, and snippets.

@ziadoz

ziadoz/log-errors.js

Created Dec 11, 2019
Embed
What would you like to do?
Log JS Errors via AJAX
// On error send to backend route which will log error into central logging service.
window.onerror = function(message, file, line) {
fetch(
'/log/js-error',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
file: file,
line: line,
message: message,
browser: navigator.userAgent,
url: window.location.href
})
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.