diff --git a/src/services/notifications/NativeNotificationService.ts b/src/services/notifications/NativeNotificationService.ts index 490a1591..9c46ff96 100644 --- a/src/services/notifications/NativeNotificationService.ts +++ b/src/services/notifications/NativeNotificationService.ts @@ -577,11 +577,12 @@ export async function refreshNotificationsWithDiagnostics(options?: { source?: string; }): Promise { const startedAt = performance.now(); - logRefreshStarted(options?.source); + const source = options?.source; + logRefreshStarted(source); if (!Capacitor.isNativePlatform()) { const errorMessage = "not a native platform"; - logRefreshFailure(startedAt, errorMessage); + logRefreshFailure(startedAt, errorMessage, undefined, source); return { ok: false, scheduledCount: 0, @@ -593,7 +594,7 @@ export async function refreshNotificationsWithDiagnostics(options?: { const auth = await getNotificationApiHeaders("refresh"); if (!auth.ok) { logSkippingRefreshDueToMissingAuth(); - logRefreshFailure(startedAt, auth.message); + logRefreshFailure(startedAt, auth.message, undefined, source); return { ok: false, scheduledCount: 0, @@ -632,7 +633,7 @@ export async function refreshNotificationsWithDiagnostics(options?: { statusText: res.statusText, errorMessage, }); - logRefreshFailure(startedAt, errorMessage, res.status); + logRefreshFailure(startedAt, errorMessage, res.status, source); return { ok: false, scheduledCount: 0, @@ -647,12 +648,12 @@ export async function refreshNotificationsWithDiagnostics(options?: { ? payload.nextNotifications.length : 0; await applyNotificationRefreshPayload(data); - logRefreshSuccess(startedAt, scheduledCount); + logRefreshSuccess(startedAt, scheduledCount, source); return { ok: true, scheduledCount }; } catch (err) { logger.error("[NativeNotificationService] Refresh failed", err); const message = err instanceof Error ? err.message : String(err); - logRefreshFailure(startedAt, message); + logRefreshFailure(startedAt, message, undefined, source); return { ok: false, scheduledCount: 0, errorMessage: message }; } } diff --git a/src/services/notifications/notificationLog.ts b/src/services/notifications/notificationLog.ts index 99070743..d8dc1298 100644 --- a/src/services/notifications/notificationLog.ts +++ b/src/services/notifications/notificationLog.ts @@ -85,21 +85,27 @@ function elapsedMsSince(startedAt: number): number { export function logRefreshSuccess( startedAt: number, scheduledCount: number, + source?: string, ): void { - logNotification( - `Refresh completed in ${Math.round(elapsedMsSince(startedAt))}ms (scheduled ${scheduledCount})`, - ); + const elapsedMs = Math.round(elapsedMsSince(startedAt)); + const message = source + ? `Refresh completed (${source}) in ${elapsedMs}ms (scheduled ${scheduledCount})` + : `Refresh completed in ${elapsedMs}ms (scheduled ${scheduledCount})`; + logNotification(message); } export function logRefreshFailure( startedAt: number, errorMessage: string, status?: number, + source?: string, ): void { const statusPart = status != null ? ` HTTP ${status}` : ""; - logNotification( - `Refresh failed in ${Math.round(elapsedMsSince(startedAt))}ms: ${errorMessage}${statusPart}`, - ); + const elapsedMs = Math.round(elapsedMsSince(startedAt)); + const message = source + ? `Refresh failed (${source}) in ${elapsedMs}ms: ${errorMessage}${statusPart}` + : `Refresh failed in ${elapsedMs}ms: ${errorMessage}${statusPart}`; + logNotification(message); } export function logNotificationClearing(method: string): void {