8000 Requesting verbose error responses from FCM backend by hiranya911 · Pull Request #226 · firebase/firebase-admin-python · GitHub
[go: up one dir, main page]

Skip to content

Requesting verbose error responses from FCM backend #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
8000 Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ scripts/cert.json
scripts/apikey.txt
htmlcov/
.pytest_cache/
.vscode/
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion firebase_admin/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8000
3 changes: 3 additions & 0 deletions tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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

Expand Down
0