How to use the pyfcm.errors.FCMServerError function in pyfcm

To help you get started, we’ve selected a few pyfcm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github olucurious / PyFCM / pyfcm / extensions / tornado.py View on Github external
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')
github olucurious / PyFCM / pyfcm / baseapi.py View on Github external
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
github olucurious / PyFCM / pyfcm / baseapi.py View on Github external
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