当前位置: 首页>>代码示例>>PHP>>正文


PHP RequestException::getCode方法代码示例

本文整理汇总了PHP中GuzzleHttp\Exception\RequestException::getCode方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestException::getCode方法的具体用法?PHP RequestException::getCode怎么用?PHP RequestException::getCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Exception\RequestException的用法示例。


在下文中一共展示了RequestException::getCode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: __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

示例3: parseException

 /**
  * @param RequestException $exception
  *
  * @return ApiException
  */
 private function parseException(RequestException $exception)
 {
     if ($exception->getCode() == 401) {
         return new ApiException($this->create401ErrorMessage($exception), $exception->getCode(), $exception);
     }
     return new ApiException($exception->getMessage(), $exception->getCode(), $exception);
 }
开发者ID:adlogix,项目名称:confluence-rest-php-client,代码行数:12,代码来源:ExceptionWrapper.php

示例4: 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

示例5: createClientException

 /**
  * @param GuzzleHttpRequestException $exception
  * @return Client\ClientException
  */
 private static function createClientException(GuzzleHttpRequestException $exception)
 {
     $exceptionArray = array(400 => 'BadRequest', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'NotFound', 405 => 'MethodNotAllowed', 406 => 'NotAcceptable');
     foreach ($exceptionArray as $item => $value) {
         if ($item === $exception->getCode()) {
             $exceptionName = __NAMESPACE__ . '\\Client\\' . $value . 'Exception';
             return new $exceptionName($exception);
         }
     }
     return new RequestException($exception);
 }
开发者ID:keika299,项目名称:chap,代码行数:15,代码来源:ExceptionFactory.php

示例6: __construct

 public function __construct(RequestException $e)
 {
     $message = $e->getMessage();
     if ($e instanceof ClientException) {
         $response = $e->getResponse();
         $responseBody = $response->getBody()->getContents();
         $this->errorDetails = $responseBody;
         $message .= ' [details] ' . $this->errorDetails;
     } elseif ($e instanceof ServerException) {
         $message .= ' [details] Zendesk may be experiencing internal issues or undergoing scheduled maintenance.';
     } elseif (!$e->hasResponse()) {
         $request = $e->getRequest();
         // Unsuccessful response, log what we can
         $message .= ' [url] ' . $request->getUri();
         $message .= ' [http method] ' . $request->getMethod();
     }
     parent::__construct($message, $e->getCode());
 }
开发者ID:keitler,项目名称:zendesk_api_client_php,代码行数:18,代码来源:ApiResponseException.php

示例7: onRequestException

 /**
  * Handles a Request Exception.
  *
  * @param RequestException $e The request exception.
  *
  * @return void
  */
 protected function onRequestException(RequestException $e)
 {
     $request = $e->getRequest();
     $response = $e->getResponse();
     if (!$response) {
         throw new RuntimeException($e->getMessage(), $e->getCode());
     }
     $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 Uphold 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:dinastyoffreedom,项目名称:uphold-sdk-php,代码行数:44,代码来源:ErrorHandler.php

示例8: getRequestExceptionParts

 /**
  * Prepares an array of important exception parts based on composition of a
  * given exception.
  *
  * @param  RequestException  $requestException
  *
  * @return array
  */
 private function getRequestExceptionParts(RequestException $requestException)
 {
     $response = $requestException->getResponse();
     $parts = [];
     $parts['reason'] = $response ? $response->getReasonPhrase() : $requestException->getMessage();
     $parts['code'] = $response ? $response->getStatusCode() : $requestException->getCode();
     $parts['body'] = $response ? $response->getBody() : null;
     return $parts;
 }
开发者ID:stevenmaguire,项目名称:trello-php,代码行数:17,代码来源:Http.php

示例9: standardizeExceptionResponse

 private function standardizeExceptionResponse(RequestException $e)
 {
     $response = new stdClass();
     $response->status = $e->getCode();
     $response->description = $e->getMessage();
     return $response;
 }
开发者ID:CoreProc,项目名称:chikka-api-sdk-php,代码行数:7,代码来源:SmsTransporter.php

示例10: handleGuzzleRequestException

 /**
  * @param RequestException $exception
  * @throws RequestFailedException
  */
 public static function handleGuzzleRequestException(RequestException $exception)
 {
     $message = sprintf('Request failed due: "%s".', $exception->getMessage());
     throw new RequestFailedException($message, $exception->getCode(), $exception);
 }
开发者ID:achse,项目名称:php-shapeshift-io-api,代码行数:9,代码来源:ResultProcessor.php

示例11: handleException

 private function handleException(RequestException $exception)
 {
     if ($exception->getCode() === self::STREAM_DOES_NOT_EXIST) {
         throw new StreamDoesNotExist($exception->getMessage());
     }
     if ($exception->getCode() === self::REQUEST_BODY_INVALID && empty(json_decode($exception->getRequest()->getBody()))) {
         throw new CannotWriteStreamWithoutEvents($exception->getMessage());
     }
     throw new EventStoreConnectionFailed($exception->getMessage());
 }
开发者ID:lzakrzewski,项目名称:http-event-store,代码行数:10,代码来源:HttpEventStore.php

示例12: httpRequestException

 /**
  * @param \GuzzleHttp\Exception\RequestException $previous
  *
  * @return \Riak\Client\Core\Transport\RiakTransportException
  */
 public static function httpRequestException(RequestException $previous)
 {
     return new self($previous->getMessage(), $previous->getCode(), $previous);
 }
开发者ID:php-riak,项目名称:riak-client,代码行数:9,代码来源:RiakTransportException.php


注:本文中的GuzzleHttp\Exception\RequestException::getCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。