Пример #1
0
 /**
  * @param Response $response
  *
  * @return \Exception
  */
 protected function handleResponse(Response $response)
 {
     if ($this->exception) {
         return $this->exception->create($response->getContent(), $response->getStatusCode());
     }
     $content = json_decode($response->getContent());
     return new \RuntimeException(sprintf('[%d] %s (%s)', $response->getStatusCode(), $content->message, $content->id));
 }
Пример #2
0
 /**
  * @param CompleteEvent $event
  *
  * @throws \RuntimeException|ExceptionInterface
  */
 protected function handleResponse(CompleteEvent $event)
 {
     $this->response = $event->getResponse();
     if ($this->response->getStatusCode() >= 200 && $this->response->getStatusCode() <= 299) {
         return;
     }
     $body = $this->response->getBody();
     $code = $this->response->getStatusCode();
     if ($this->exception) {
         throw $this->exception->create($body, $code);
     }
     $content = $this->response->json();
     throw new \RuntimeException(sprintf('[%d] %s (%s)', $code, $content->message, $content->id), $code);
 }
Пример #3
0
 /**
  * @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);
 }