diff --git a/.gitignore b/.gitignore index b3adf5c17..4880bc525 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ scripts/cert.json scripts/apikey.txt htmlcov/ .pytest_cache/ +.vscode/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c0b779c..a16a89182 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Unreleased -- [added] `messaging.AndroidNotification`type now supports channel_id. +- [fixed] FCM errors sent by the back-end now include more details + that are helpful when debugging problems. +- [added] `messaging.AndroidNotification` type now supports `channel_id`. - [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 96b38295e..3dcee05ed 100644 --- a/firebase_admin/messaging.py +++ b/firebase_admin/messaging.py @@ -889,7 +889,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 a31f16447..3ffb187e4 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -1046,6 +1046,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, @@ -1060,6 +1061,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 @@ -1076,6 +1078,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