# Path: autopush/constants.py
# DEFAULT_ROUTER_TIMEOUT = 3
# 
# Path: autopush/exceptions.py
# class RouterException(AutopushException):
#     """Exception if routing has failed, may include a custom status_code and
#     body to write to the response.
# 
#     """
#     def __init__(self, message, status_code=500, response_body="",
#                  router_data=None, headers=None, log_exception=True,
#                  errno=None, logged_status=None, **kwargs):
#         """Create a new RouterException"""
#         super(AutopushException, self).__init__(message)
#         self.status_code = status_code
#         self.headers = {} if headers is None else headers
#         self.log_exception = log_exception
#         self.response_body = response_body or message
#         self.errno = errno
#         self.logged_status = logged_status
#         self.extra = kwargs


import json
import treq
from oauth2client.service_account import ServiceAccountCredentials
from twisted.logger import Logger
from twisted.internet.error import (ConnectError, TimeoutError)
from autopush.constants import DEFAULT_ROUTER_TIMEOUT
from autopush.exceptions import RouterException
        # Failures:
        #   { "error":
        #       { "status": str
        #         "message": str
        #         "code": u64
        #         "details: [
        #             {"errorCode": str,
        #              "@type": str},
        #             {"fieldViolations": [
        #               {"field": str,
        #                "description": str}
        #              ],
        #              "type", str
        #             }
        #          ]
        #      }
        #  }
        # (Failures are a tad more verbose)
        if 500 <= self.code <= 599:
            self.retry_message = content
            return self
        try:
            data = json.loads(content)
            if self.code in (400, 403, 404, 410) or data.get('error'):
                # Having a hard time finding information about how some
                # things are handled in FCM, e.g. retransmit requests.
                # For now, catalog them as errors and provide back-pressure.
                err = data.get("error")
                if err.get("status") == "NOT_FOUND":
                    raise FCMNotFoundError("FCM recipient no longer available")

# Path: autopush/constants.py
# DEFAULT_ROUTER_TIMEOUT = 3
# 
# Path: autopush/exceptions.py
# class RouterException(AutopushException):
#     """Exception if routing has failed, may include a custom status_code and
#     body to write to the response.
# 
#     """
#     def __init__(self, message, status_code=500, response_body="",
#                  router_data=None, headers=None, log_exception=True,
#                  errno=None, logged_status=None, **kwargs):
#         """Create a new RouterException"""
#         super(AutopushException, self).__init__(message)
#         self.status_code = status_code
#         self.headers = {} if headers is None else headers
#         self.log_exception = log_exception
#         self.response_body = response_body or message
#         self.errno = errno
#         self.logged_status = logged_status
#         self.extra = kwargs


# Path: autopush/router/fcmv1client.py
import json
import treq
from oauth2client.service_account import ServiceAccountCredentials
from twisted.logger import Logger
from twisted.internet.error import (ConnectError, TimeoutError)
from autopush.constants import DEFAULT_ROUTER_TIMEOUT
from autopush.exceptions import RouterException

        # Failures:
        #   { "error":
        #       { "status": str
        #         "message": str
        #         "code": u64
        #         "details: [
        #             {"errorCode": str,
        #              "@type": str},
        #             {"fieldViolations": [
        #               {"field": str,
        #                "description": str}
        #              ],
        #              "type", str
        #             }
        #          ]
        #      }
        #  }
        # (Failures are a tad more verbose)
        if 500 <= self.code <= 599:
            self.retry_message = content
            return self
        try:
            data = json.loads(content)
            if self.code in (400, 403, 404, 410) or data.get('error'):
                # Having a hard time finding information about how some
                # things are handled in FCM, e.g. retransmit requests.
                # For now, catalog them as errors and provide back-pressure.
                err = data.get("error")
                if err.get("status") == "NOT_FOUND":
                    raise FCMNotFoundError("FCM recipient no longer available")

                raise RouterException(