From 3beec1f7527892733e45f15c9817da1faa68e3e4 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Fri, 30 Nov 2018 14:07:08 -0800 Subject: [PATCH] Requesting verbose error responses from FCM backend --- CHANGELOG.md | 2 ++ firebase_admin/messaging.py | 4 +++- tests/test_messaging.py | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7fcf53de..2a7802f7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- [fixed] FCM errors sent by the back-end now include more details + that are helpful when debugging problems. - [fixed] Fixing error handling in FCM. The SDK now checks the key type.googleapis.com/google.firebase.fcm.v1.FcmError to set error code. - [fixed] Ensuring that `UserRecord.tokens_valid_after_time` always diff --git a/firebase_admin/messaging.py b/firebase_admin/messaging.py index 28e80935c..34b6877c0 100644 --- a/firebase_admin/messaging.py +++ b/firebase_admin/messaging.py @@ -885,7 +885,9 @@ def send(self, message, dry_run=False): if dry_run: data['validate_only'] = True try: - resp = self._client.body('post', url=self._fcm_url, json=data, timeout=self._timeout) + headers = {'X-GOOG-API-FORMAT-VERSION': '2'} + resp = self._client.body( + 'post', url=self._fcm_url, headers=headers, json=data, timeout=self._timeout) except requests.exceptions.RequestException as error: if error.response is not None: self._handle_fcm_error(error) diff --git a/tests/test_messaging.py b/tests/test_messaging.py index 5b3a17232..69eebb65b 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -1039,6 +1039,7 @@ def test_send_dry_run(self): assert len(recorder) == 1 assert recorder[0].method == 'POST' assert recorder[0].url == self._get_url('explicit-project-id') + assert recorder[0].headers['X-GOOG-API-FORMAT-VERSION'] == '2' body = { 'message': messaging._MessagingService.encode_message(msg), 'validate_only': True, @@ -1053,6 +1054,7 @@ def test_send(self): assert len(recorder) == 1 assert recorder[0].method == 'POST' assert recorder[0].url == self._get_url('explicit-project-id') + assert recorder[0].headers['X-GOOG-API-FORMAT-VERSION'] == '2' assert recorder[0]._extra_kwargs['timeout'] is None body = {'message': messaging._MessagingService.encode_message(msg)} assert json.loads(recorder[0].body.decode()) == body @@ -1069,6 +1071,7 @@ def test_send_error(self, status): assert len(recorder) == 1 assert recorder[0].method == 'POST' assert recorder[0].url == self._get_url('explicit-project-id') + assert recorder[0].headers['X-GOOG-API-FORMAT-VERSION'] == '2' body = {'message': messaging._MessagingService.JSON_ENCODER.default(msg)} assert json.loads(recorder[0].body.decode()) == body