Skip to content

Commit 69c940c

Browse files
authored
fix(fcm): Updated topic management error format (firebase#417)
* fix(fcm): Updated topic management error format * Better default error messages * Removed redundant variable initializer
1 parent 6a26c15 commit 69c940c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

firebase_admin/messaging.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,12 @@ def _handle_iid_error(self, error):
453453
except ValueError:
454454
pass
455455

456-
# IID error response format: {"error": "some error message"}
457-
msg = data.get('error')
458-
if not msg:
456+
# IID error response format: {"error": "ErrorCode"}
457+
code = data.get('error')
458+
msg = None
459+
if code:
460+
msg = 'Error while calling the IID service: {0}'.format(code)
461+
else:
459462
msg = 'Unexpected HTTP response with status: {0}; body: {1}'.format(
460463
error.response.status_code, error.response.content.decode())
461464

tests/test_messaging.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2286,7 +2286,7 @@ def test_subscribe_to_topic_error(self, status, exc_type):
22862286
status=status, payload=self._DEFAULT_ERROR_RESPONSE)
22872287
with pytest.raises(exc_type) as excinfo:
22882288
messaging.subscribe_to_topic('foo', 'test-topic')
2289-
assert str(excinfo.value) == 'error_reason'
2289+
assert str(excinfo.value) == 'Error while calling the IID service: error_reason'
22902290
assert len(recorder) == 1
22912291
assert recorder[0].method == 'POST'
22922292
assert recorder[0].url == self._get_url('iid/v1:batchAdd')
@@ -2318,7 +2318,7 @@ def test_unsubscribe_from_topic_error(self, status, exc_type):
23182318
status=status, payload=self._DEFAULT_ERROR_RESPONSE)
23192319
with pytest.raises(exc_type) as excinfo:
23202320
messaging.unsubscribe_from_topic('foo', 'test-topic')
2321-
assert str(excinfo.value) == 'error_reason'
2321+
assert str(excinfo.value) == 'Error while calling the IID service: error_reason'
23222322
assert len(recorder) == 1
23232323
assert recorder[0].method == 'POST'
23242324
assert recorder[0].url == self._get_url('iid/v1:batchRemove')

0 commit comments

Comments
 (0)