Skip to content

Instantly share code, notes, and snippets.

@omrilotan
Created April 5, 2020 14:04
Show Gist options
  • Save omrilotan/12746c379c918f4600193a2402afdae5 to your computer and use it in GitHub Desktop.
Save omrilotan/12746c379c918f4600193a2402afdae5 to your computer and use it in GitHub Desktop.
const errorsHistory = [];
function abortErrorReport(message, file, line, column, error) {
// Close the log behind a rollout mechanism to protect your infrastructure
if (!errorLoggingEnabled) return true;
// Limit the amount of errors from one page
if (errorsHistory.length > 10) return true;
// Send the same error twice from the same page can create false multiplications
if (errorsHistory.includes(message)) return true;
errorsHistory.push(message);
// A page may be considered stale if it's been open for over, lets say, an hour
if (window.performance.now() > 36e5) return true;
// Add more rules that suit your consideration
return false;
}
function myOnErrorHandler(...args) {
if(abortErrorReport(...args)) {
return;
}
...
sendError(record);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment