protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response) {
         if ($response->isSuccessful()) {
             return false;
         } else {
             return isset($this->errorCodes[$response->getStatusCode()]) ? true : null;
         }
     }
 }
 /**
  * Get the response of the query.
  * Will be the json decoded data if success, else the error message.
  *
  * @return array|string
  */
 public function getResponse()
 {
     if (false === $this->response->isSuccessful()) {
         return $this->response->getMessage();
     }
     return $this->response->json();
 }
 /**
  * @param \Guzzle\Http\Message\Response $response
  */
 public function __construct(\Guzzle\Http\Message\Response $response)
 {
     if ($response->isSuccessful()) {
         $this->response = $response->json();
         foreach ($this->response as $key => $value) {
             $this->response[$key] = $value;
         }
     } else {
         // TODO: Error handling
     }
 }
 /**
  * @param Event $event
  *
  * @throws \RuntimeException|ExceptionInterface
  */
 protected function handleResponse(Event $event)
 {
     $this->response = $event['response'];
     if ($this->response->isSuccessful()) {
         return;
     }
     $body = $this->response->getBody(true);
     $code = $this->response->getStatusCode();
     if ($this->exception) {
         throw $this->exception->create($body, $code);
     }
     $content = json_decode($body);
     throw new \RuntimeException(sprintf('[%d] %s (%s)', $code, $content->message, $content->id), $code);
 }
 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response) {
         //Short circuit the rest of the checks if it was successful
         if ($response->isSuccessful()) {
             return false;
         } else {
             if (isset($this->errorCodes[$response->getStatusCode()])) {
                 if ($response->getHeader("Retry-After")) {
                     return $response->getHeader("Retry-After")->__toString();
                 } else {
                     return self::$defaultRetryAfter;
                 }
             } else {
                 return null;
             }
         }
     }
 }
 /**
  * @return bool
  */
 private function isHttpErrorFatal(Response $response, $expectedResponseContentType)
 {
     return $response->isSuccessful() && $response->getContentType() != $expectedResponseContentType;
 }
Exemple #7
0
 /**
  * @covers Guzzle\Http\Message\Response::isSuccessful
  */
 public function testIsSuccessful()
 {
     $response = new Response(200);
     $this->assertTrue($response->isSuccessful());
     $response = new Response(403);
     $this->assertFalse($response->isSuccessful());
 }
 public function canCacheResponse(Response $response)
 {
     return $response->isSuccessful() && $response->canCache();
 }
Exemple #9
0
 private function processResponse(Response $response)
 {
     if (!$response->isSuccessful()) {
         throw new ApiServerException($response->getMessage(), $response->getStatusCode());
     }
     if (self::FORMAT_ARRAY === $this->outputFormat) {
         return $response->json();
     }
     return $response->getBody(true);
 }
Exemple #10
0
 /**
  * Log a message based on a request and response
  *
  * @param RequestInterface $request  Request to log
  * @param Response         $response Response to log
  */
 private function log(RequestInterface $request, Response $response = null)
 {
     $message = '';
     if ($this->settings & self::LOG_CONTEXT) {
         // Log common contextual information
         $message = $request->getHost() . ' - "' . $request->getMethod() . ' ' . $request->getResource() . ' ' . strtoupper($request->getScheme()) . '/' . $request->getProtocolVersion() . '"';
         // If a response is set, then log additional contextual information
         if ($response) {
             $message .= sprintf(' - %s %s - %s %s %s', $response->getStatusCode(), $response->getContentLength() ?: 0, $response->getInfo('total_time'), $response->getInfo('speed_upload'), $response->getInfo('speed_download'));
         }
     }
     // Check if we are logging anything that will come from cURL
     if ($request->getParams()->get('curl_handle') && ($this->settings & self::LOG_DEBUG || $this->settings & self::LOG_HEADERS || $this->settings & self::LOG_BODY)) {
         // If context logging too, then add a new line for cleaner messages
         if ($this->settings & self::LOG_CONTEXT) {
             $message .= "\n";
         }
         // Filter cURL's verbose output based on config settings
         $message .= $this->parseCurlLog($request);
         // Log the response body if the response is available
         if ($this->settings & self::LOG_BODY && $response) {
             if ($request->getParams()->get('response_wire')) {
                 $message .= (string) $request->getParams()->get('response_wire');
             } else {
                 $message .= $response->getBody(true);
             }
         }
     }
     // Send the log message to the adapter, adding a category and host
     $priority = $response && !$response->isSuccessful() ? LOG_ERR : LOG_DEBUG;
     $this->logAdapter->log(trim($message), $priority, array('category' => 'guzzle.request', 'host' => $this->hostname));
 }
 /**
  * {@inheritdoc}
  */
 public function isSuccessful()
 {
     return $this->response->isSuccessful();
 }
 public function __construct(RequestInterface $request, HttpResponse $response)
 {
     parent::__construct($request, $response->xml());
     $this->isSuccessful = $response->isSuccessful();
 }
Exemple #13
0
 /**
  * @return bool
  */
 public function isSuccess()
 {
     return $this->guzzleResponse->isSuccessful();
 }