How to use the sparkpost.tornado.exceptions.SparkPostAPIException function in sparkpost

To help you get started, we’ve selected a few sparkpost 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 SparkPost / python-sparkpost / sparkpost / tornado / base.py View on Github external
def request(self, method, uri, headers, **kwargs):
        if "data" in kwargs:
            kwargs["body"] = kwargs.pop("data")
        client = AsyncHTTPClient()
        try:
            response = yield client.fetch(uri, method=method, headers=headers,
                                          **kwargs)
        except HTTPError as ex:
            raise SparkPostAPIException(ex.response)
        if response.code == 204:
            raise gen.Return(True)
        if response.code == 200:
            result = None
            # noinspection PyBroadException
            try:
                result = json.loads(response.body.decode("utf-8"))
            # TODO: select exception to catch here
            except:  # noqa: E722
                pass
            if result:
                if 'results' in result:
                    raise gen.Return(result['results'])
                raise gen.Return(result)
        raise SparkPostAPIException(response)
github SparkPost / python-sparkpost / sparkpost / tornado / base.py View on Github external
raise SparkPostAPIException(ex.response)
        if response.code == 204:
            raise gen.Return(True)
        if response.code == 200:
            result = None
            # noinspection PyBroadException
            try:
                result = json.loads(response.body.decode("utf-8"))
            # TODO: select exception to catch here
            except:  # noqa: E722
                pass
            if result:
                if 'results' in result:
                    raise gen.Return(result['results'])
                raise gen.Return(result)
        raise SparkPostAPIException(response)