Log push send outcomes, not just failures

notifyHouseholdParents only logged on error -- a fully successful send
produced zero output, which is indistinguishable from the two silent
early-return paths (push not configured, no subscriptions for the
household). Made all three paths log explicitly, so "grep logs for push"
actually tells you what happened instead of leaving success and several
failure modes looking identical.
This commit is contained in:
ort
2026-08-15 17:03:00 -04:00
parent aa21709f3d
commit 7faec49a42
+12 -2
View File
@@ -25,10 +25,16 @@ const listSubscriptionsForHouseholdStmt = db.prepare(`
const deleteSubscriptionStmt = db.prepare('DELETE FROM push_subscriptions WHERE id = ?'); const deleteSubscriptionStmt = db.prepare('DELETE FROM push_subscriptions WHERE id = ?');
async function notifyHouseholdParents(householdId, payload) { async function notifyHouseholdParents(householdId, payload) {
if (!pushReady) return; if (!pushReady) {
console.log('[push] skipped — push not configured/ready');
return;
}
const subs = listSubscriptionsForHouseholdStmt.all(householdId); const subs = listSubscriptionsForHouseholdStmt.all(householdId);
if (subs.length === 0) return; if (subs.length === 0) {
console.log(`[push] skipped — no subscriptions for household ${householdId}`);
return;
}
const body = JSON.stringify(payload); const body = JSON.stringify(payload);
@@ -43,6 +49,7 @@ async function notifyHouseholdParents(householdId, payload) {
.catch((err) => { .catch((err) => {
if (err.statusCode === 404 || err.statusCode === 410) { if (err.statusCode === 404 || err.statusCode === 410) {
deleteSubscriptionStmt.run(sub.id); deleteSubscriptionStmt.run(sub.id);
console.error('[push] subscription gone, pruned', sub.id, err.statusCode);
} else { } else {
console.error('[push] send failed', sub.id, err.statusCode, err.message); console.error('[push] send failed', sub.id, err.statusCode, err.message);
} }
@@ -51,6 +58,9 @@ async function notifyHouseholdParents(householdId, payload) {
) )
); );
const succeeded = results.filter((r) => r.status === 'fulfilled').length;
console.log(`[push] sent to ${succeeded}/${subs.length} subscription(s) for household ${householdId}`);
return results; return results;
} }