improve monitoring the solution

This commit is contained in:
Peter Maquiran
2024-07-30 15:52:07 +01:00
parent 8f0625eed4
commit edcaf951c2
11 changed files with 167 additions and 27 deletions
+42
View File
@@ -62,3 +62,45 @@ platformBrowserDynamic().bootstrapModule(AppModule)
defineCustomElements(window);
console.log(environment.version.lastCommitTime)
// error-capture.js
// Function to capture error details
function captureError(message, sourceURL, lineno, colno, error) {
const errorDetails = {
message: message || 'Unknown error',
sourceURL: sourceURL || 'Unknown source',
lineNumber: lineno || 'Unknown line',
columnNumber: colno || 'Unknown column',
stack: error ? error.stack : 'No stack trace'
};
// Log to console
console.error('Error Details:', JSON.stringify(errorDetails, null, 2));
// Optionally, send to server or write to a local storage
// Example: Sending to server (requires server-side handling)
// fetch('/log-error', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(errorDetails)
// });
// Example: Storing in localStorage
// localStorage.setItem('errorLog', JSON.stringify(errorDetails));
}
// Capture errors from synchronous code
window.onerror = function(message, sourceURL, lineno, colno, error) {
captureError(message, sourceURL, lineno, colno, error);
// Return true to prevent default handling (optional)
return true;
};
// Capture errors from promise rejections
window.addEventListener('unhandledrejection', function(event) {
const { reason } = event;
captureError(reason.message || 'Unhandled rejection', 'Unknown source', 'Unknown line', 'Unknown column', reason);
});