forked from jsnbuchanan/crowd-funder-for-time-pwa
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.
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { initializeApp } from "./main.common";
|
|
import { App } from "@capacitor/app";
|
|
import router from "./router";
|
|
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
|
|
let pendingDeepLink: string | null = null;
|
|
|
|
// Initialize API error handling
|
|
window.addEventListener('unhandledrejection', (event) => {
|
|
if (event.reason?.response) {
|
|
handleApiError(event.reason, event.reason.config?.url || 'unknown');
|
|
}
|
|
});
|
|
|
|
// Create reusable handler function
|
|
const handleDeepLink = async (data: { url: string }) => {
|
|
try {
|
|
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');
|
|
}
|
|
|
|
const path = parts[1]; // This will be "claim/01JMAAFZRNSRTQ0EBSD70A8E1H"
|
|
console.log("[Capacitor Deep Link] Parsed path:", path);
|
|
|
|
// Map parameterized routes
|
|
const paramRoutes = {
|
|
'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) {
|
|
console.log(`[Capacitor Deep Link] Matched route: ${routeName}, param: ${match[1]}`);
|
|
await router.replace({
|
|
name: routeName,
|
|
params: { id: match[1] }
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
await router.replace('/' + path);
|
|
} catch (error) {
|
|
console.error("[Capacitor Deep Link] Error:", error);
|
|
handleApiError(error, 'deep-link');
|
|
}
|
|
};
|
|
|
|
// Register listener
|
|
App.addListener("appUrlOpen", handleDeepLink);
|
|
|
|
console.log("[Capacitor] Mounting app");
|
|
app.mount("#app");
|
|
console.log("[Capacitor] App mounted"); |