public function __construct(Response $response)
 {
     $this->response = $response;
     // TODO: log this cleanly...
     var_dump($this->response);
     parent::__construct($response->getMessage(), $response->getStatusCode());
 }
Exemple #2
0
 /**
  *
  * @param \Kazoo\SDK $sdk
  */
 public function __construct(SDK $sdk)
 {
     $this->setSDK($sdk);
     $sdk = $this->getSDK();
     $options = $sdk->getOptions();
     $handler = HandlerStack::create();
     $handler->push(Middleware::mapRequest(function (Request $request) {
         $sdk = $this->getSDK();
         $token = $sdk->getAuthToken()->getToken();
         return $request->withHeader('X-Auth-Token', $token);
     }));
     $handler->push(Middleware::mapResponse(function (GuzzleResponse $guzzleResponse) {
         $response = new Response($guzzleResponse);
         $code = $response->getStatusCode();
         switch ($code) {
             case 400:
                 throw new Validation($response);
             case 401:
                 // invalid creds
                 throw new Unauthenticated($response);
             case 402:
                 // not enough credit
                 throw new Billing($response);
             case 403:
                 // forbidden
                 throw new Unauthorized($response);
             case 404:
                 // not found
                 throw new NotFound($response);
             case 405:
                 // invalid method
                 throw new InvalidMethod($response);
             case 409:
                 // conflicting documents
                 throw new Conflict($response);
             case 429:
                 // too many requests
                 throw new RateLimit($response);
             default:
                 if ($code >= 400 && $code < 500) {
                     throw new ApiException($response);
                 } else {
                     if ($code > 500) {
                         throw new HttpException($response);
                     }
                 }
         }
         return $guzzleResponse;
     }));
     $options['handler'] = $handler;
     $this->setClient(new GuzzleClient($options));
 }
 /**
  *
  * @param \Guzzle\Common\Event $event
  */
 public function onRequestError(Event $event)
 {
     $request = $event['request'];
     $response = new Response($request->getResponse());
     $code = $response->getStatusCode();
     switch ($code) {
         case 400:
             throw new Validation($response);
         case 401:
             // invalid creds
             throw new Unauthenticated($response);
         case 402:
             // not enough credit
             throw new Billing($response);
         case 403:
             // forbidden
             throw new Unauthorized($response);
         case 404:
             // not found
             throw new NotFound($response);
         case 405:
             // invalid method
             throw new InvalidMethod($response);
         case 409:
             // conflicting documents
             throw new Conflict($response);
         case 429:
             // too many requests
             throw new RateLimit($response);
         default:
             if ($code >= 400 && $code < 500) {
                 throw new ApiException($response);
             } else {
                 if ($code > 500) {
                     throw new HttpException($response);
                 }
             }
     }
 }
 public function __construct(Response $response)
 {
     $this->response = $response;
     error_log(print_r($this->response, true));
     parent::__construct($response->getMessage(), $response->getStatusCode());
 }