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


PHP RequestException::getMessage方法代碼示例

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


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

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

示例4: failBecauseOfHttpError

    protected function failBecauseOfHttpError(RequestException $e)
    {
        $this->fail(sprintf(<<<'EOL'
failed to create user: HTTP ERROR
%s
EOL
, $e->getMessage()));
    }
開發者ID:RiskioFr,項目名稱:codeception-auth0-module,代碼行數:8,代碼來源:Auth0.php

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

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

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

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

示例9: __construct

 public function __construct(RequestException $e)
 {
     $this->request = $e->getRequest();
     $this->response = $e->getResponse();
     $simpleMessage = $e->getMessage();
     $code = 0;
     if ($this->response) {
         try {
             $decodedJson = Utils::jsonDecode((string) $this->response->getBody(), true);
             if ($decodedJson && isset($decodedJson['errorType'])) {
                 $simpleMessage = $decodedJson['errorType'] . ' ' . $decodedJson['message'];
             }
         } catch (\InvalidArgumentException $e) {
             // Not Json
         }
         $code = $this->response->getStatusCode();
     }
     $responseDescription = $this->response ? (string) $this->response : 'none';
     $requestDescription = $this->request ? (string) $this->request : 'none';
     $message = sprintf("%s\n\nRequest: %s\n\nResponse: %s\n\n", $simpleMessage, $requestDescription, $responseDescription);
     parent::__construct($message, $code, $e);
 }
開發者ID:sitra-tourisme,項目名稱:sitra-api-php,代碼行數:22,代碼來源:SitraException.php

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

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

示例12: facebookApiException

 private function facebookApiException($message, RequestInterface $request, ResponseInterface $response = null, RequestException $exception = null)
 {
     if (null !== $exception) {
         $message .= $exception->getMessage();
     }
     if (null !== $this->logger) {
         $context = array('request' => $request);
         if (null !== $response) {
             $context['response'] = (string) $response;
         }
         $this->logger->error($message, $context);
     }
     return new FacebookApiException($message);
 }
開發者ID:buldezir,項目名稱:FacebookAuthenticationAdapter,代碼行數:14,代碼來源:GuzzleFacebookApi.php

示例13: createException

 protected function createException(GuzzleRequestException $e)
 {
     $statusCode = $e->getResponse()->getStatusCode();
     switch ($statusCode) {
         case 401:
             $authInfo = $this->parseAuthHeader($e->getResponse()->getHeader('www-authenticate'));
             $code = array_key_exists('error', $authInfo) ? $authInfo['error'] : 401;
             $message = array_key_exists('error_description', $authInfo) ? $authInfo['error_description'] : $e->getMessage();
             return new UnauthorizedException($message, $code, $e);
         default:
             return new ApiRequestException('Api Request failed: ' . $e->getMessage(), 0, $e);
     }
 }
開發者ID:solcre,項目名稱:columnis-express,代碼行數:13,代碼來源:ApiService.php

示例14: apiException

 /**
  * @param RequestException $e
  * @return ApiException
  */
 private function apiException(RequestException $e)
 {
     $message = $e->hasResponse() ? $e->getResponse()->getBody()->getContents() : $e->getMessage();
     $code = $e->hasResponse() ? $e->getResponse()->getStatusCode() : null;
     return new ApiException($message, $code);
 }
開發者ID:m1x0n,項目名稱:helpscout-docs-api-php,代碼行數:10,代碼來源:DocsApiClient.php

示例15: manageException

 /**
  * Manage exception in http call.
  *
  * @param RequestException $exception
  *
  * @throw RuntimeException.
  */
 protected function manageException(RequestException $exception)
 {
     $errorMessage = $exception->getMessage() . ' Request: ' . $exception->getRequest();
     if ($exception->hasResponse()) {
         $errorMessage .= ' ErrorCode: ' . $exception->getResponse()->getStatusCode() . ' Response: ' . $exception->getResponse()->getBody();
     }
     throw new RuntimeException($errorMessage);
 }
開發者ID:abevallez,項目名稱:mountebank-php,代碼行數:15,代碼來源:ServiceVirtualization.php


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