Exemplo n.º 1
0
 /**
  * Handle stuff when an error occur
  *
  * @param string $body
  * @param int $httpStatus
  *
  * @return Response
  * @throws \Happyr\ApiClient\Exceptions\HttpException
  */
 protected function handleError(Response $response)
 {
     if ($this->configuration->debug) {
         echo 'Exception: ' . $response->getBody() . "\n";
     }
     $exception = new HttpException($response);
     if ($this->configuration->enableExceptions) {
         //throw exceptions
         throw $exception;
     }
     return $exception->getEmptyResponse();
 }
Exemplo n.º 2
0
 /**
  * @param Response $response
  */
 public function __construct(Response $response)
 {
     $this->response = $response;
     $message = $response->getBody();
     try {
         $xml = @simplexml_load_string($response);
         if (is_object($xml)) {
             $message = $xml->exception['message'];
         }
     } catch (\Exception $e) {
         $message = substr($response, 0, 200);
     }
     parent::__construct($message, $response->getCode());
 }