Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
method='POST',
headers=self.request_headers(),
body=payload
)
response = yield self.http_client.fetch(request)
if response.code == 200:
yield self.parse_response(response)
return
elif response.code == 401:
raise AuthenticationError('There was an error authenticating the sender account')
elif response.code == 400:
raise InternalPackageError('Unknown internal error')
else:
raise FCMServerError('FCM server is temporarily unavailable')
if multicast_id:
response_dict['multicast_ids'].append(multicast_id)
response_dict['success'] += success
response_dict['failure'] += failure
response_dict['canonical_ids'] += canonical_ids
response_dict['results'].extend(results)
response_dict['topic_message_id'] = message_id
elif response.status_code == 401:
raise AuthenticationError("There was an error authenticating the sender account")
elif response.status_code == 400:
raise InvalidDataError(response.text)
elif response.status_code == 404:
raise FCMNotRegisteredError("Token not registered")
else:
raise FCMServerError("FCM server is temporarily unavailable")
return response_dict
AuthenticationError: error authenticating the sender account
InvalidDataError: data passed to FCM was incorrecly structured
"""
response_dict = {
'multicast_ids': [],
'success': 0,
'failure': 0,
'canonical_ids': 0,
'results': [],
'topic_message_id': None
}
for response in self.send_request_responses:
if response.status_code == 200:
if 'content-length' in response.headers and int(response.headers['content-length']) <= 0:
raise FCMServerError("FCM server connection error, the response is empty")
else:
parsed_response = response.json()
multicast_id = parsed_response.get('multicast_id', None)
success = parsed_response.get('success', 0)
failure = parsed_response.get('failure', 0)
canonical_ids = parsed_response.get('canonical_ids', 0)
results = parsed_response.get('results', [])
message_id = parsed_response.get('message_id', None) # for topic messages
if message_id:
success = 1
if multicast_id:
response_dict['multicast_ids'].append(multicast_id)
response_dict['success'] += success
response_dict['failure'] += failure
response_dict['canonical_ids'] += canonical_ids