diff --git a/firebase_admin/messaging.py b/firebase_admin/messaging.py index e4e223091..217cf0a56 100644 --- a/firebase_admin/messaging.py +++ b/firebase_admin/messaging.py @@ -453,9 +453,12 @@ def _handle_iid_error(self, error): except ValueError: pass - # IID error response format: {"error": "some error message"} - msg = data.get('error') - if not msg: + # IID error response format: {"error": "ErrorCode"} + code = data.get('error') + msg = None + if code: + msg = 'Error while calling the IID service: {0}'.format(code) + else: msg = 'Unexpected HTTP response with status: {0}; body: {1}'.format( error.response.status_code, error.response.content.decode()) diff --git a/tests/test_messaging.py b/tests/test_messaging.py index 6e776cc5f..6333aad46 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -2286,7 +2286,7 @@ def test_subscribe_to_topic_error(self, status, exc_type): status=status, payload=self._DEFAULT_ERROR_RESPONSE) with pytest.raises(exc_type) as excinfo: messaging.subscribe_to_topic('foo', 'test-topic') - assert str(excinfo.value) == 'error_reason' + assert str(excinfo.value) == 'Error while calling the IID service: error_reason' assert len(recorder) == 1 assert recorder[0].method == 'POST' assert recorder[0].url == self._get_url('iid/v1:batchAdd') @@ -2318,7 +2318,7 @@ def test_unsubscribe_from_topic_error(self, status, exc_type): status=status, payload=self._DEFAULT_ERROR_RESPONSE) with pytest.raises(exc_type) as excinfo: messaging.unsubscribe_from_topic('foo', 'test-topic') - assert str(excinfo.value) == 'error_reason' + assert str(excinfo.value) == 'Error while calling the IID service: error_reason' assert len(recorder) == 1 assert recorder[0].method == 'POST' assert recorder[0].url == self._get_url('iid/v1:batchRemove')