/**
  * {@inheritdoc}
  */
 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response && $response->isClientError()) {
         $parts = $this->exceptionParser->parse($request, $response);
         return isset(self::$throttlingExceptions[$parts['code']]) ? true : null;
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function parse(RequestInterface $request, Response $response)
 {
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => null, 'parsed' => null);
     if ($body = $response->getBody(true)) {
         $this->parseBody(new \SimpleXMLElement($body), $data);
     } else {
         $this->parseHeaders($request, $response, $data);
     }
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function parse(RequestInterface $request, Response $response)
 {
     // Build array of default error data
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => (string) $response->getHeader('x-amzn-RequestId'), 'parsed' => null);
     // Parse the json and normalize key casings
     if (null !== ($json = json_decode($response->getBody(true), true))) {
         $data['parsed'] = array_change_key_case($json);
     }
     // Do additional, protocol-specific parsing and return the result
     $data = $this->doParse($data, $response);
     // Remove "Fault" suffix from exception names
     if (isset($data['code']) && strpos($data['code'], 'Fault')) {
         $data['code'] = preg_replace('/^([a-zA-Z]+)Fault$/', '$1', $data['code']);
     }
     return $data;
 }
Example #4
0
 /**
  * Factory method to create a new response exception based on the response code.
  *
  * @param RequestInterface $request  Request
  * @param Response         $response Response received
  *
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     if ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new $class($message);
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response && $response->isClientError()) {
         $parts = $this->exceptionParser->parse($request, $response);
         if (!isset($this->retryable[$parts['code']]) || !$request->getClient()) {
             return null;
         }
         /** @var $client AwsClientInterface */
         $client = $request->getClient();
         // Only retry if the credentials can be refreshed
         if (!$client->getCredentials() instanceof AbstractRefreshableCredentials) {
             return null;
         }
         // Resign the request using new credentials
         $client->getSignature()->signRequest($request, $client->getCredentials()->setExpiration(-1));
         // Retry immediately with no delay
         return 0;
     }
 }