Phase 1: Remove obsolete files and standardize all pages
- Standardize script loading on faq, privacy, returns, shipping-info pages - Archive 14 unused JS files (cart-functions, shopping, cart.js, enhanced versions, etc.) - Archive 2 unused CSS files (responsive-enhanced, responsive-fixes) - All pages now use consistent script loading order - Eliminated shopping.js dependency (not needed after standardization)
This commit is contained in:
63
website/public/assets/js/archive/error-handler.js
Normal file
63
website/public/assets/js/archive/error-handler.js
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Frontend Error Handler
|
||||
* Centralized error handling and logging
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
class ErrorHandler {
|
||||
constructor() {
|
||||
this.errors = [];
|
||||
this.maxErrors = 100;
|
||||
this.productionMode = window.location.hostname !== "localhost";
|
||||
}
|
||||
|
||||
log(context, error, level = "error") {
|
||||
const errorEntry = {
|
||||
timestamp: new Date().toISOString(),
|
||||
context,
|
||||
message: error?.message || error,
|
||||
level,
|
||||
stack: error?.stack,
|
||||
};
|
||||
|
||||
this.errors.push(errorEntry);
|
||||
if (this.errors.length > this.maxErrors) {
|
||||
this.errors.shift();
|
||||
}
|
||||
|
||||
// Only log to console in development
|
||||
if (!this.productionMode && level === "error") {
|
||||
console.error(`[${context}]`, error);
|
||||
} else if (!this.productionMode && level === "warn") {
|
||||
console.warn(`[${context}]`, error);
|
||||
}
|
||||
}
|
||||
|
||||
getErrors() {
|
||||
return [...this.errors];
|
||||
}
|
||||
|
||||
clearErrors() {
|
||||
this.errors = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Global error handler
|
||||
window.ErrorHandler = window.ErrorHandler || new ErrorHandler();
|
||||
|
||||
// Global error event handler
|
||||
window.addEventListener("error", (event) => {
|
||||
window.ErrorHandler.log(
|
||||
"GlobalError",
|
||||
event.error || event.message,
|
||||
"error"
|
||||
);
|
||||
});
|
||||
|
||||
// Unhandled promise rejection handler
|
||||
window.addEventListener("unhandledrejection", (event) => {
|
||||
window.ErrorHandler.log("UnhandledRejection", event.reason, "error");
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user