Skip to content
Snippets Groups Projects
Commit 5b8bd1ce authored by Luko van der Maas's avatar Luko van der Maas
Browse files

Merge branch 'fix/firebase-error' into 'master'

Fix removal of Firebase Admin SDK error

Closes #940

See merge request !1381

(cherry picked from commit 027b7ee2)

5bde87dd Fix removal of Firebase Admin SDK error
parent 168dc3aa
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ from django.conf import settings
from django.db import models
from django.utils.translation import override
from django.utils.translation import ugettext_lazy as _
from firebase_admin import messaging
from firebase_admin import messaging, exceptions
from utils.translation import MultilingualField, ModelTranslateMeta
......@@ -174,15 +174,18 @@ class Message(models.Model, metaclass=ModelTranslateMeta):
messaging.send(message, dry_run=kwargs.get(
'dry_run', False))
success_total += 1
except messaging.ApiCallError as e:
except messaging.UnregisteredError:
failure_total += 1
Device.objects.filter(
registration_id=reg_id
).delete()
except exceptions.InvalidArgumentError:
failure_total += 1
Device.objects.filter(
registration_id=reg_id
).update(active=False)
except exceptions.FirebaseError:
failure_total += 1
d = Device.objects.filter(registration_id=reg_id)
if e.code == 'registration-token-not-registered':
d.delete()
elif (e.code == 'invalid-argument'
or e.code == 'invalid-recipient'
or e.code == 'invalid-registration-token'):
d.update(active=False)
self.sent = True
self.success = success_total
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment