Beispiel #1
0
        def on_response(response):
            exc = response.exception()
            if exc:
                if isinstance(exc, httpclient.HTTPError):
                    need_credentials, aws_error = self._process_error(exc)
                    if need_credentials and \
                            not self._auth_config.local_credentials:
                        self._auth_config.reset()
                        if not recursed:

                            def on_retry(retry):
                                if not self._future_exception(retry, future):
                                    future.set_result(retry.result())

                            request = self.fetch(method, path, query_args,
                                                 headers, body, True)
                            self._ioloop.add_future(request, on_retry)
                            return
                    future.set_exception(aws_error if aws_error else exc)
                else:
                    LOGGER.error('Error making request: %s', exc)
                    future.set_exception(
                        exceptions.RequestException(error=exc))
            else:
                future.set_result(response.result())
Beispiel #2
0
    def fetch(self,
              method,
              path='/',
              query_args=None,
              headers=None,
              body=b'',
              recursed=False):
        """Executes a request, returning an
        :py:class:`HTTPResponse <tornado.httpclient.HTTPResponse>`.

        If an error occurs during the fetch, we raise an
        :py:class:`HTTPError <tornado.httpclient.HTTPError>` unless the
        ``raise_error`` keyword argument is set to ``False``.

        :param str method: HTTP request method
        :param str path: The request path
        :param dict query_args: Request query arguments
        :param dict headers: Request headers
        :param bytes body: The request body
        :param bool recursed: Internally invoked if it's a recursive fetch
        :rtype: :class:`~tornado.httpclient.HTTPResponse`
        :raises: :class:`~tornado.httpclient.HTTPError`
        :raises: :class:`~tornado_aws.exceptions.NoCredentialsError`
        :raises: :class:`~tornado_aws.exceptions.AWSError`

        """
        if self._auth_config.needs_credentials():
            self._auth_config.refresh()

        request = self._create_request(method, path, query_args, headers, body)

        try:
            result = self._client.fetch(request, raise_error=True)
            return result
        except (OSError, socket.error) as error:
            LOGGER.error('Error making request: %s', error)
            raise exceptions.RequestException(error=error)
        except httpclient.HTTPError as error:
            need_credentials, aws_error = self._process_error(error)
            if need_credentials and not self._auth_config.local_credentials:
                self._auth_config.reset()
                if not recursed:
                    return self.fetch(method, path, query_args, headers, body,
                                      True)
            raise aws_error if aws_error else error
Beispiel #3
0
 def test_tornado_aws_request_exception(self):
     self.create_table_expecting_raise(
         dynamodb.RequestException,
         aws_exceptions.RequestException(error=OSError))