8000 Requesting verbose error responses from FCM backend (#226) · ClarkDing/firebase-admin-python@eb0119b · GitHub
[go: up one dir, main page]

Skip to content

Commit eb0119b

Browse files
authored
Requesting verbose error responses from FCM backend (firebase#226)
1 parent 92652ff commit eb0119b

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ scripts/cert.json
1111
scripts/apikey.txt
1212
htmlcov/
1313
.pytest_cache/
14+
.vscode/

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Unreleased
22

3-
- [added] `messaging.AndroidNotification`type now supports channel_id.
3+
- [fixed] FCM errors sent by the back-end now include more details
4+
that are helpful when debugging problems.
5+
- [added] `messaging.AndroidNotification` type now supports `channel_id`.
46
- [fixed] Fixing error handling in FCM. The SDK now checks the key
57
type.googleapis.com/google.firebase.fcm.v1.FcmError to set error code.
68
- [fixed] Ensuring that `UserRecord.tokens_valid_after_time` always

firebase_admin/messaging.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,9 @@ def send(self, message, dry_run=False):
889889
if dry_run:
890890
data['validate_only'] = True
891891
try:
892-
resp = self._client.body('post', url=self._fcm_url, json=data, timeout=self._timeout)
892+
headers = {'X-GOOG-API-FORMAT-VERSION': '2'}
893+
resp = self._client.body(
894+
'post', url=self._fcm_url, headers=headers, json=data, timeout=self._timeout)
893895
except requests.exceptions.RequestException as error:
894896
if error.response is not None:
895897
self._handle_fcm_error(error)

tests/test_messaging.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ def test_send_dry_run(self):
10461046
assert len(recorder) == 1
10471047
assert recorder[0].method == 'POST'
10481048
assert recorder[0].url == self._get_url('explicit-project-id')
1049+
assert recorder[0].headers['X-GOOG-API-FORMAT-VERSION'] == '2'
10491050
body = {
10501051
'message': messaging._MessagingService.encode_message(msg),
10511052
'validate_only': True,
@@ -1060,6 +1061,7 @@ def test_send(self):
10601061
assert len(recorder) == 1
10611062
assert recorder[0].method == 'POST'
10621063
assert recorder[0].url == self._get_url('explicit-project-id')
1064+
assert recorder[0].headers['X-GOOG-API-FORMAT-VERSION'] == '2'
10631065
assert recorder[0]._extra_kwargs['timeout'] is None
10641066
body = {'message': messaging._MessagingService.encode_message(msg)}
10651067
assert json.loads(recorder[0].body.decode()) == body
@@ -1076,6 +1078,7 @@ def test_send_error(self, status):
10761078
assert len(recorder) == 1
10771079
assert recorder[0].method == 'POST'
10781080
assert recorder[0].url == self._get_url('explicit-project-id')
1081+
assert recorder[0].headers['X-GOOG-API-FORMAT-VERSION'] == '2'
10791082
body = {'message': messaging._MessagingService.JSON_ENCODER.default(msg)}
10801083
assert json.loads(recorder[0].body.decode()) == body
10811084

0 commit comments

Comments
 (0)
0