From caa171637404506e73e9f8f747e0ac1df8260e2b Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <0xsysr3ll@pm.me> Date: Sat, 15 Nov 2025 21:48:30 +0100 Subject: [PATCH] fix(webpush): improve push notification error handling Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> --- server/lib/notifications/agents/webpush.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/server/lib/notifications/agents/webpush.ts b/server/lib/notifications/agents/webpush.ts index fcb7416e0..57bae4650 100644 --- a/server/lib/notifications/agents/webpush.ts +++ b/server/lib/notifications/agents/webpush.ts @@ -188,19 +188,30 @@ class WebPushAgent notificationPayload ); } catch (e) { + const statusCode = (e as any).statusCode || (e as any).status; + const isPermanentFailure = statusCode === 410 || statusCode === 404; + logger.error( - 'Error sending web push notification; removing subscription', + isPermanentFailure + ? 'Error sending web push notification; removing invalid subscription' + : 'Error sending web push notification (transient error, keeping subscription)', { label: 'Notifications', recipient: pushSub.user.displayName, type: Notification[type], subject: payload.subject, - errorMessage: e.message, + errorMessage: (e as Error).message || String(e), + statusCode: statusCode || 'unknown', + errorBody: (e as any).body || (e as any).response?.body, + endpoint: pushSub.endpoint.substring(0, 50) + '...', } ); - // Failed to send notification so we need to remove the subscription - userPushSubRepository.remove(pushSub); + // Only remove subscription for permanent failures + // Transient errors should not remove the subscription + if (isPermanentFailure) { + await userPushSubRepository.remove(pushSub); + } } };