chore: add debug logging for push notifications
This commit is contained in:
@@ -39,6 +39,7 @@ export async function sendPlanNotification(planId: string, message: string, webh
|
||||
});
|
||||
|
||||
if (subscriptions.length > 0) {
|
||||
console.log(`[Push] Found ${subscriptions.length} subscriptions for plan ${planId}`);
|
||||
const payload = {
|
||||
title: "Cat Sitting Planner",
|
||||
body: message,
|
||||
@@ -56,12 +57,24 @@ export async function sendPlanNotification(planId: string, message: string, webh
|
||||
|
||||
subscriptions.forEach(sub => {
|
||||
promises.push((async () => {
|
||||
const res = await sendPushNotification(sub, payload);
|
||||
if (!res.success && (res.statusCode === 410 || res.statusCode === 404)) {
|
||||
await prisma.pushSubscription.delete({ where: { id: sub.id } });
|
||||
try {
|
||||
console.log(`[Push] Sending to endpoint ${sub.endpoint.slice(0, 20)}...`);
|
||||
const res = await sendPushNotification(sub, payload);
|
||||
console.log(`[Push] Result for ${sub.endpoint.slice(0, 20)}...:`, res);
|
||||
if (!res.success) {
|
||||
console.error(`[Push] Failed for endpoint: ${res.statusCode}`);
|
||||
if (res.statusCode === 410 || res.statusCode === 404) {
|
||||
console.log(`[Push] Deleting stale subscription`);
|
||||
await prisma.pushSubscription.delete({ where: { id: sub.id } });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`[Push] Error inside loop:`, err);
|
||||
}
|
||||
})());
|
||||
});
|
||||
} else {
|
||||
console.log(`[Push] No subscriptions found for plan ${planId}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch/send push subscriptions", e);
|
||||
|
||||
Reference in New Issue
Block a user