forked from jsnbuchanan/crowd-funder-for-time-pwa
feat(logging): enhance debug logging across app
Improves application logging and error tracking: - Add structured logging in main.common.ts for app initialization - Enhance API error handling with detailed context in services - Add deep link debugging in Capacitor platform - Improve plan service logging with retry information - Update endorser server logs for better cache debugging Technical changes: - Replace console.error with info for non-critical cache misses - Add component context to global error handler - Add detailed logging for plan loading and retries - Improve deep link route matching logs - Add mount state logging for Capacitor This improves debugging capabilities across web and mobile platforms.
This commit is contained in:
@@ -5,6 +5,9 @@ import { handleApiError } from "./services/api";
|
||||
import { loadPlanWithRetry } from "./services/plan";
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
|
||||
console.log("[Capacitor] Starting initialization");
|
||||
console.log("[Capacitor] Platform:", process.env.VITE_PLATFORM);
|
||||
|
||||
const app = initializeApp();
|
||||
|
||||
// Store initial deep link if app is not ready
|
||||
@@ -20,44 +23,32 @@ window.addEventListener('unhandledrejection', (event) => {
|
||||
// Create reusable handler function
|
||||
const handleDeepLink = async (data: { url: string }) => {
|
||||
try {
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
console.log("[Capacitor Deep Link] START Handler");
|
||||
console.log("[Capacitor Deep Link] Received URL:", data.url);
|
||||
console.log("[Capacitor Deep Link] START Handler");
|
||||
console.log("[Capacitor Deep Link] Received URL:", data.url);
|
||||
|
||||
// Wait for router to be ready
|
||||
await router.isReady();
|
||||
|
||||
// Parse the custom URL scheme
|
||||
const parts = data.url.split('://');
|
||||
if (parts.length !== 2) {
|
||||
throw new Error('Invalid URL format');
|
||||
}
|
||||
|
||||
// Wait for app to be mounted
|
||||
if (!app._container) {
|
||||
console.log("[Capacitor Deep Link] Waiting for app mount");
|
||||
await new Promise<void>((resolve) => {
|
||||
const interval = setInterval(() => {
|
||||
if (app._container) {
|
||||
clearInterval(interval);
|
||||
resolve();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
const url = new URL(data.url);
|
||||
const path = url.pathname.substring(1);
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
console.log("[Capacitor Deep Link] Parsed path:", path);
|
||||
}
|
||||
const path = parts[1]; // This will be "claim/01JMAAFZRNSRTQ0EBSD70A8E1H"
|
||||
console.log("[Capacitor Deep Link] Parsed path:", path);
|
||||
|
||||
// Map parameterized routes
|
||||
const paramRoutes = {
|
||||
'claim': /^claim\/(.+)$/,
|
||||
'claim': /^claim\/(.+)$/, // Updated pattern without leading slash
|
||||
};
|
||||
|
||||
// Check if path matches any parameterized route
|
||||
for (const [routeName, pattern] of Object.entries(paramRoutes)) {
|
||||
const match = path.match(pattern);
|
||||
if (match) {
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
console.log(`[Capacitor Deep Link] Matched route: ${routeName}, param: ${match[1]}`);
|
||||
}
|
||||
await router.push({
|
||||
console.log(`[Capacitor Deep Link] Matched route: ${routeName}, param: ${match[1]}`);
|
||||
await router.replace({
|
||||
name: routeName,
|
||||
params: { id: match[1] }
|
||||
});
|
||||
@@ -65,7 +56,7 @@ const handleDeepLink = async (data: { url: string }) => {
|
||||
}
|
||||
}
|
||||
|
||||
await router.push('/' + path);
|
||||
await router.replace('/' + path);
|
||||
} catch (error) {
|
||||
console.error("[Capacitor Deep Link] Error:", error);
|
||||
handleApiError(error, 'deep-link');
|
||||
@@ -75,5 +66,6 @@ const handleDeepLink = async (data: { url: string }) => {
|
||||
// Register listener
|
||||
App.addListener("appUrlOpen", handleDeepLink);
|
||||
|
||||
// Mount app
|
||||
console.log("[Capacitor] Mounting app");
|
||||
app.mount("#app");
|
||||
console.log("[Capacitor] App mounted");
|
||||
Reference in New Issue
Block a user