fix: remove Topic header, add push response logging
- Remove Topic header (causes issues with Apple push service) - Log push response status codes for debugging - Log endpoint prefix on errors for identification - Auto-cleanup 410 (gone) subscriptions on success path too
This commit is contained in:
@@ -169,17 +169,20 @@ func (h *Handler) SendPush(ctx context.Context, userID string, payload map[strin
|
|||||||
VAPIDPrivateKey: h.vapidPriv,
|
VAPIDPrivateKey: h.vapidPriv,
|
||||||
TTL: 86400,
|
TTL: 86400,
|
||||||
Urgency: webpush.UrgencyHigh,
|
Urgency: webpush.UrgencyHigh,
|
||||||
Topic: userID,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.Error("failed to send push", "error", err, "user_id", userID)
|
h.logger.Error("failed to send push", "error", err, "user_id", userID, "endpoint", endpoint[:min(60, len(endpoint))])
|
||||||
if resp != nil && resp.StatusCode == 410 {
|
if resp != nil && resp.StatusCode == 410 {
|
||||||
h.db.ExecContext(ctx, `DELETE FROM push_subscriptions WHERE endpoint = $1`, endpoint)
|
h.db.ExecContext(ctx, `DELETE FROM push_subscriptions WHERE endpoint = $1`, endpoint)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
|
h.logger.Info("push sent", "user_id", userID, "status", resp.StatusCode, "endpoint", endpoint[:min(60, len(endpoint))])
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
if resp.StatusCode == 410 {
|
||||||
|
h.db.ExecContext(ctx, `DELETE FROM push_subscriptions WHERE endpoint = $1`, endpoint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,7 +249,6 @@ func (h *Handler) SendChannelNotification(ctx context.Context, channelID, author
|
|||||||
VAPIDPrivateKey: h.vapidPriv,
|
VAPIDPrivateKey: h.vapidPriv,
|
||||||
TTL: 86400,
|
TTL: 86400,
|
||||||
Urgency: webpush.UrgencyHigh,
|
Urgency: webpush.UrgencyHigh,
|
||||||
Topic: userID,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.Error("failed to send push", "error", err, "user_id", userID)
|
h.logger.Error("failed to send push", "error", err, "user_id", userID)
|
||||||
|
|||||||
Reference in New Issue
Block a user