當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RequestException::getResponse方法代碼示例

本文整理匯總了PHP中GuzzleHttp\Exception\RequestException::getResponse方法的典型用法代碼示例。如果您正苦於以下問題:PHP RequestException::getResponse方法的具體用法?PHP RequestException::getResponse怎麽用?PHP RequestException::getResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GuzzleHttp\Exception\RequestException的用法示例。


在下文中一共展示了RequestException::getResponse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onRequestException

 /**
  * Handles a Request Exception.
  *
  * @param RequestException $e The request exception.
  *
  * @return void
  */
 protected function onRequestException(RequestException $e)
 {
     $request = $e->getRequest();
     $response = $e->getResponse();
     $statusCode = $response->getStatusCode();
     $isClientError = $response->isClientError();
     $isServerError = $response->isServerError();
     if ($isClientError || $isServerError) {
         $content = $response->getContent();
         $error = $response->getError();
         $description = $response->getErrorDescription();
         if (400 === $statusCode) {
             throw new BadRequestException($description, $error, $statusCode, $response, $request);
         }
         if (401 === $statusCode) {
             $otp = (string) $response->getHeader('X-Bitreserve-OTP');
             if ('required' === $otp) {
                 $description = 'Two factor authentication is enabled on this account';
                 throw new TwoFactorAuthenticationRequiredException($description, $error, $statusCode, $response, $request);
             }
             throw new AuthenticationRequiredException($description, $error, $statusCode, $response, $request);
         }
         if (404 === $statusCode) {
             $description = sprintf('Object or route not found: %s', $request->getPath());
             throw new NotFoundException($description, 'not_found', $statusCode, $response, $request);
         }
         if (429 === $statusCode) {
             $rateLimit = $response->getApiRateLimit();
             $description = sprintf('You have reached Bitreserve API limit. API limit is: %s. Your remaining requests will be reset at %s.', $rateLimit['limit'], date('Y-m-d H:i:s', $rateLimit['reset']));
             throw new ApiLimitExceedException($description, $error, $statusCode, $response, $request);
         }
         throw new RuntimeException($description, $error, $statusCode, $response, $request);
     }
 }
開發者ID:byrnereese,項目名稱:bitreserve-sdk-php,代碼行數:41,代碼來源:ErrorHandler.php

示例2: parseRequestException

 /**
  * @param   RequestException $ex
  * @return  AccessDeniedException|EntityNotFoundException|EntityValidationException|RequiredFieldMissingException|UnauthorizedClientException|CaravanaHttpException
  */
 public static function parseRequestException(RequestException $ex)
 {
     $code = $ex->getCode();
     $body = json_decode($ex->getResponse()->getBody()->getContents(), true);
     if (CaravanaExceptionFactory::isEntityValidationException($code, $body)) {
         return new EntityValidationException(AU::get($body['Entity']), AU::get($body['field']), AU::get($body['reason']), AU::get($body['providedValue']), $ex->getPrevious());
     } else {
         if (CaravanaExceptionFactory::isRequiredFieldMissingException($code, $body)) {
             return new RequiredFieldMissingException(AU::get($body['Entity']), AU::get($body['field']), $ex->getPrevious());
         } else {
             if (CaravanaExceptionFactory::isUnauthorizedClientException($code, $body)) {
                 return new UnauthorizedClientException($ex->getMessage(), $ex->getPrevious());
             } else {
                 if (CaravanaExceptionFactory::isAccessDeniedException($code, $body)) {
                     return new AccessDeniedException($ex->getMessage(), $ex->getPrevious());
                 } else {
                     if (CaravanaExceptionFactory::isEntityNotFoundException($code, $body)) {
                         return new EntityNotFoundException(AU::get($body['Entity']), AU::get($body['field']), AU::get($body['providedValue']), $ex->getPrevious());
                     }
                 }
             }
         }
     }
     //  Give up and default it to CaravanaException
     return new CaravanaHttpException($ex->getMessage(), $ex->getCode(), null, $ex->getPrevious());
 }
開發者ID:caravanarentals,項目名稱:base-php-wrapper,代碼行數:30,代碼來源:CaravanaExceptionFactory.php

示例3: createException

 /**
  * Converts a Guzzle exception into an Httplug exception.
  *
  * @param RequestException $exception
  *
  * @return Exception
  */
 private function createException(RequestException $exception)
 {
     if ($exception->hasResponse()) {
         return new HttpException($exception->getMessage(), $exception->getRequest(), $exception->getResponse(), $exception);
     }
     return new NetworkException($exception->getMessage(), $exception->getRequest(), $exception);
 }
開發者ID:Nyholm,項目名稱:guzzle6-adapter,代碼行數:14,代碼來源:Guzzle6HttpAdapter.php

示例4: handleException

 private function handleException(RequestException $exception)
 {
     if ($exception instanceof BadResponseException) {
         return $exception->getResponse();
     }
     throw new Exception($exception->getMessage());
 }
開發者ID:matsubo,項目名稱:spike-php,代碼行數:7,代碼來源:GuzzleHttpClient.php

示例5: create

 /**
  * @internal
  * @param RequestException $e
  * @return AccessDeniedException|ApiException|AuthenticationException|ConflictingStateException|
  * MethodNotAllowedException|NotFoundException|RateLimitExceededException|UnsupportedAcceptHeaderException|
  * UnsupportedContentTypeException|ValidationException
  */
 public static function create(RequestException $e)
 {
     if ($response = $e->getResponse()) {
         switch ($response->getStatusCode()) {
             case 400:
                 return new ValidationException($e);
             case 401:
                 return new AuthenticationException($e);
             case 403:
                 return new AccessDeniedException($e);
             case 404:
                 return new NotFoundException($e);
             case 405:
                 return new MethodNotAllowedException($e);
             case 406:
                 return new UnsupportedAcceptHeaderException($e);
             case 409:
                 return new ConflictingStateException($e);
             case 415:
                 return new UnsupportedContentTypeException($e);
             case 429:
                 return new RateLimitExceededException($e);
         }
     }
     return new ApiException($e);
 }
開發者ID:mpclarkson,項目名稱:freshdesk-php-sdk,代碼行數:33,代碼來源:ApiException.php

示例6: manejar_excepcion_request

 private function manejar_excepcion_request(RequestException $e)
 {
     $msg = $e->getRequest() . "\n";
     if ($e->hasResponse()) {
         $msg .= $e->getResponse() . "\n";
     }
     throw new toba_error($msg);
 }
開發者ID:emma5021,項目名稱:toba,代碼行數:8,代碼來源:rest_arai_usuarios.php

示例7: throwRequestException

 /**
  * throwRequestException
  *
  * @param \GuzzleHttp\Exception\RequestException $e
  * @param string $className
  * @throws Exceptions\RequestException
  */
 protected function throwRequestException($e, $className)
 {
     $response = $e->getResponse();
     $rawBody = (string) $response->getBody();
     $body = json_decode((string) $rawBody);
     $body = $body === null ? $rawBody : $body;
     $exception = new $className($e->getMessage(), $e->getCode());
     $exception->setBody($body);
     throw $exception;
 }
開發者ID:jerray,項目名稱:qcloud-cos-php-sdk,代碼行數:17,代碼來源:RestClient.php

示例8: handleError

 protected function handleError(RequestException $e)
 {
     $response = $e->getResponse();
     switch ($response->getStatusCode()) {
         case 404:
             throw new Exceptions\NotFoundException($this->getResponseError($response));
         default:
             throw new Exceptions\MeshException($this->getResponseError($response));
     }
 }
開發者ID:iainkydd-oneiota,項目名稱:MeshSDK,代碼行數:10,代碼來源:DomainObject.php

示例9: testHasRequestAndResponse

 public function testHasRequestAndResponse()
 {
     $req = new Request('GET', '/');
     $res = new Response(200);
     $e = new RequestException('foo', $req, $res);
     $this->assertSame($req, $e->getRequest());
     $this->assertSame($res, $e->getResponse());
     $this->assertTrue($e->hasResponse());
     $this->assertEquals('foo', $e->getMessage());
 }
開發者ID:ChenOhayon,項目名稱:sitepoint_codes,代碼行數:10,代碼來源:RequestExceptionTest.php

示例10: __construct

 public function __construct(RequestException $e, $message = '')
 {
     $prefix = $message ?: "Bad response from the WIU API";
     if ($e->getCode()) {
         $prefix .= " (HTTP status {$e->getCode()})";
     }
     $response = $e->getResponse();
     $body = $response->json();
     $message = isset($body['message']) ? $body['message'] : $response->getReasonPhrase();
     parent::__construct("{$prefix}: {$message}", $e->getCode(), null);
 }
開發者ID:wondernetwork,項目名稱:wiuphp,代碼行數:11,代碼來源:APIException.php

示例11: handle

 /**
  * Captch known exceptions
  * @param RequestException $e
  * @throws BolException
  * @throws \Exception
  */
 public function handle(RequestException $e)
 {
     $response = $e->getResponse();
     $statusCode = $response->getStatusCode();
     $this->handleStatusCode($statusCode);
     $body = $response->getBody(true);
     $message = $this->xmlParser->parse($body);
     if (isset($message['ErrorCode'])) {
         throw new BolException($message['ErrorMessage'], $message['ErrorCode']);
     }
     throw new \Exception("Unknown error occurred. Status code: {$response->getStatusCode()}.");
 }
開發者ID:koenreiniers,項目名稱:bol-sdk,代碼行數:18,代碼來源:ExceptionHandler.php

示例12: wrap

 /**
  * Wraps an API exception in the appropriate domain exception.
  *
  * @param RequestException $e The API exception
  *
  * @return HttpException
  */
 public static function wrap(RequestException $e)
 {
     $response = $e->getResponse();
     if ($errors = self::errors($response)) {
         $class = self::exceptionClass($response, $errors[0]);
         $message = implode(', ', array_map('strval', $errors));
     } else {
         $class = self::exceptionClass($response);
         $message = $e->getMessage();
     }
     return new $class($message, $errors, $e->getRequest(), $response, $e);
 }
開發者ID:perfect-coin,項目名稱:coinbase-php,代碼行數:19,代碼來源:HttpException.php

示例13: factoryException

 /**
  * @param RequestException $exception
  *
  * @return ApnsException
  */
 private static function factoryException(RequestException $exception)
 {
     $response = $exception->getResponse();
     if (null === $response) {
         return new ApnsException('Unknown network error', 0, $exception);
     }
     try {
         $contents = $response->getBody()->getContents();
     } catch (\Exception $e) {
         return new ApnsException('Unknown network error', 0, $e);
     }
     return ExceptionFactory::factoryException($response->getStatusCode(), $contents, $exception);
 }
開發者ID:gepo,項目名稱:apns-http2,代碼行數:18,代碼來源:GuzzleHandler.php

示例14: __construct

 public function __construct(RequestException $e)
 {
     $response = $e->getResponse();
     $message = $response->getReasonPhrase() . " [status code] " . $response->getStatusCode();
     $level = floor($response->getStatusCode() / 100);
     // Check if business-level error message
     // https://developer.zendesk.com/rest_api/docs/core/introduction#requests
     if ($level == '4') {
         $responseBody = $response->getBody()->getContents();
         $this->errorDetails = $responseBody;
         $message .= ' [details] ' . $this->errorDetails;
     } elseif ($level == '5') {
         $message .= ' [details] Zendesk may be experiencing internal issues or undergoing scheduled maintenance.';
     }
     parent::__construct($message, $response->getStatusCode());
 }
開發者ID:rscott-mv,項目名稱:zendesk_api_client_php,代碼行數:16,代碼來源:ApiResponseException.php

示例15: __construct

 public function __construct(RequestException $e)
 {
     $response = $e->getResponse();
     $message = $response->getReasonPhrase();
     $level = floor($response->getStatusCode() / 100);
     // Check if business-level error message
     // https://developer.zendesk.com/rest_api/docs/core/introduction#requests
     if ($response->getHeaderLine('Content-Type') == 'application/json; charset=UTF-8') {
         $responseBody = json_decode($response->getBody()->getContents());
         $this->errorDetails = $responseBody->details;
         $message = $responseBody->description . "\n" . 'Errors: ' . print_r($this->errorDetails, true);
     } elseif ($level == '5') {
         $message = 'Zendesk may be experiencing internal issues or undergoing scheduled maintenance.';
     }
     parent::__construct($message, $response->getStatusCode());
 }
開發者ID:jingteamleads,項目名稱:zendesk_api_client_php,代碼行數:16,代碼來源:ApiResponseException.php


注:本文中的GuzzleHttp\Exception\RequestException::getResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。