From 3aada9949d51024a92a8b5c6cb70d12f9c3cac16 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 21 Dec 2025 19:59:48 +0000
Subject: [PATCH] =auth refactored via rest, referral system set up for Jane, some javascript consolidation
---
assets/js/concise/ErrorHandler.js | 112 ++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 73 insertions(+), 39 deletions(-)
diff --git a/assets/js/dash/ErrorHandler.js b/assets/js/concise/ErrorHandler.js
similarity index 81%
rename from assets/js/dash/ErrorHandler.js
rename to assets/js/concise/ErrorHandler.js
index 7de1073..029b37b 100644
--- a/assets/js/dash/ErrorHandler.js
+++ b/assets/js/concise/ErrorHandler.js
@@ -144,37 +144,66 @@
return defaultMessages[type] || defaultMessages.unknown;
}
- /**
- * Log error to server
- */
- async logErrorToServer(type, message, context) {
- try {
- if (!this.options.apiUrl) return;
+ /**
+ * Log error to server with enhanced context
+ */
+ async logErrorToServer(type, message, context) {
+ try {
+ if (!this.options.apiUrl) return;
- const data = new FormData();
- data.append('error_type', type);
- data.append('message', message);
- data.append('context', JSON.stringify({
- ...context,
- url: window.location.href,
- userAgent: navigator.userAgent,
- timestamp: new Date().toISOString()
- }));
+ // Enhanced context with component tracking
+ const enhancedContext = {
+ ...context,
+ url: window.location.href,
+ pathname: window.location.pathname,
+ userAgent: navigator.userAgent,
+ timestamp: new Date().toISOString(),
+ viewport: `${window.innerWidth}x${window.innerHeight}`,
+ component: context.component || this.extractComponentFromStack(context.stack),
+ method: context.method || this.extractMethodFromStack(context.stack),
+ stack: context.stack || (context.error?.stack),
+ isLoggedIn: window.auth.isAuthenticated(),
+ source: 'frontend'
+ };
- // Use fetch with no-cors to ensure this always succeeds
- // even if there are CORS issues
- await fetch(`${this.options.apiUrl}errors/log`, {
- method: 'POST',
- headers: {
- 'X-WP-Nonce': window.feedSettings?.nonce || ''
- },
- body: data
- });
- } catch (e) {
- // Silently fail - we don't want errors in error reporting
- console.warn('Failed to log error to server', e);
- }
- }
+ const data = new FormData();
+ data.append('error_type', type);
+ data.append('message', message);
+ data.append('context', JSON.stringify(enhancedContext));
+
+ await fetch(`${this.options.apiUrl}errors/log`, {
+ method: 'POST',
+ headers: {
+ 'X-WP-Nonce': window.auth.getNonce()
+ },
+ body: data
+ });
+ } catch (e) {
+ console.warn('Failed to log error to server', e);
+ }
+ }
+
+ /**
+ * Extract component name from error stack
+ */
+ extractComponentFromStack(stack) {
+ if (!stack) return 'Unknown';
+
+ // Try to extract class/component name from stack trace
+ const match = stack.match(/at\s+(\w+)\./);
+ return match ? match[1] : 'Unknown';
+ }
+
+ /**
+ * Extract method name from error stack
+ */
+ extractMethodFromStack(stack) {
+ if (!stack) return null;
+
+ // Try to extract method name
+ const match = stack.match(/at\s+\w+\.(\w+)\s+/);
+ return match ? match[1] : null;
+ }
/**
* Display error notification
@@ -213,8 +242,8 @@
*/
handleAuthError() {
// Redirect to login page if user isn't logged in
- if (window.feedSettings && window.feedSettings.loginUrl) {
- window.location.href = window.feedSettings.loginUrl;
+ if (window.jvbSettings && window.jvbSettings.loginUrl) {
+ window.location.href = window.jvbSettings.loginUrl;
return;
}
@@ -345,14 +374,19 @@
});
}
}
-document.addEventListener('DOMContentLoaded', function () {
- window.jvbError = new ErrorHandler({
- api: jvbSettings.api,
- logToServer: true,
- displayNotifications: true,
- notificationDuration: 5000,
- retryEnabled: true,
- maxRetries: 3
+document.addEventListener('DOMContentLoaded', async function () {
+ window.auth.subscribe((event) => {
+ if (event === 'auth-loaded') {
+ window.jvbError = new ErrorHandler({
+ api: jvbSettings.api,
+ logToServer: true,
+ displayNotifications: true,
+ notificationDuration: 5000,
+ retryEnabled: true,
+ maxRetries: 3
+ });
+ }
});
+
});
--
Gitblit v1.10.0