Skip to content

Commit

Permalink
Better logging for send_message_to_fcm_device (#4814)
Browse files Browse the repository at this point in the history
  • Loading branch information
vstpme authored Aug 13, 2024
1 parent 01f7007 commit 4528dc1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions engine/apps/mobile_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests
from django.conf import settings
from firebase_admin.exceptions import FirebaseError
from firebase_admin.messaging import AndroidConfig, APNSConfig, APNSPayload, Message, UnregisteredError
from firebase_admin.messaging import AndroidConfig, APNSConfig, APNSPayload, Message, SendResponse, UnregisteredError
from requests import HTTPError
from rest_framework import status

Expand Down Expand Up @@ -49,9 +49,12 @@ def send_message_to_fcm_device(device: "FCMDevice", message: Message) -> bool:
https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
"""
response = device.send_message(message)
logger.debug(f"FCM response: {response}")

if isinstance(response, FirebaseError):
if isinstance(response, SendResponse):
logger.debug(
f"FCM response: success={response.success} message_id={response.message_id} exception={response.exception}"
)
elif isinstance(response, FirebaseError):
logger.exception(
f"FCM error occured in mobile_app.utils.send_message_to_fcm_device fcm_device_info={device} "
f"firebase_error_code={response._code} firebase_error_cause={response._cause} "
Expand All @@ -63,6 +66,9 @@ def send_message_to_fcm_device(device: "FCMDevice", message: Message) -> bool:
return False

raise response
else:
logger.debug(f"FCM response: {response}")

return True


Expand Down

0 comments on commit 4528dc1

Please sign in to comment.