Web Push: Error when sending notification to unsubscribed browser
See original GitHub issueGot Web Push up and running pretty well now, but there seems to be one major flaw in my implementation: If someone unsubscribes from notifications, I get a 410 error and my production app shows an Internal Server Error if I try to send them a notification.
To reproduce:
- Register a browser for web push
- Unregister the service worker on the browser
- Trigger a Web Push notification to a set of devices which includes the browser which has unsubscribed
Result:
Internal Server Error: (URI)
WebPushError at (URI)
Push failed: 410 Gone
Response body:push subscription has unsubscribed or expired.
What’s the best way to avoid this error? I’m planning to put my notification sending in a Celery task to make the site more responsive, which should hide the error from the user, but I’d like to avoid this error. Does it require a fix in django-push-notifications, or is there something I should be doing app-side?
(Perhaps @goinnn encountered this? Sorry for calling on you specifically!)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Web Push Troubleshooting - OneSignal Documentation
403 & 404 Service Worker Errors ... After you try subscribing to your site, if you see a 403 or 404 error in...
Read more >410 push subscription has unsubscribed or expired
Our web push notification was just working fine but recently we noticed that the end points are expiring in less than one day...
Read more >How to Unsubscribe from Push Notifications - SendPulse
Method 1. By Managing Notifications in Your Browser. Go to the browser menu and select "Settings." In the "Privacy and security" section ...
Read more >A Website is Sending Me Push Notifications. How do I ...
To unsubscribe, follow the instructions in this article corresponding to your browser (Chrome, Firefox, Opera, Safari) and platform (Android).
Read more >How to Unsubscribe from Push Notifications on Chrome
Method #2: Unsubscribe from the Website Sending You Notifications ... And you should be unsubscribed from any future web push notifications by ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I agree, push_messages could return something like:
{ 'devices': device_count, 'success': success_count, 'error': error_count, 'errors': [ { 'device': device_id, 'error': { 'code': error_code, 'msg': error_msg } } ] }This code is a pretty robust solution I think:
It does the following:
This works well from my app, but perhaps it should go into django-push-notifications somewhere?