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


PHP RequestException::getRequest方法代码示例

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


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

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

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

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

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

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

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

示例8: createRequestException

 /**
  * @param RequestException $e
  *
  * @return ClientError|ServerError
  */
 private function createRequestException(RequestException $e)
 {
     $response = $e->getResponse();
     $responseBody = $response->getBody()->getContents();
     try {
         $status = $this->serializer->deserialize($responseBody, Status::class, 'json');
     } catch (\RuntimeException $serializerException) {
         $status = new Status(Status::FAILURE, $responseBody);
     }
     $exceptionClass = $e instanceof ClientException ? ClientError::class : ServerError::class;
     return new $exceptionClass($status, $e->getRequest());
 }
开发者ID:sroze,项目名称:kubernetes-client,代码行数:17,代码来源:HttpConnector.php

示例9: create401ErrorMessage

 /**
  * @param RequestException $exception
  *
  * @return string
  */
 private function create401ErrorMessage(RequestException $exception)
 {
     $request = $exception->getRequest();
     $response = $exception->getResponse();
     return $this->getExceptionMessage($request, $response);
 }
开发者ID:adlogix,项目名称:confluence-rest-php-client,代码行数:11,代码来源:ExceptionWrapper.php

示例10: formatRequestException

 /**
  * @author WN
  * @param Exception\RequestException $e
  * @return array
  */
 private function formatRequestException(Exception\RequestException $e)
 {
     return ['message' => $e->getMessage(), 'request' => ['headers' => $e->getRequest()->getHeaders(), 'body' => $e->getRequest()->getBody()->getContents(), 'method' => $e->getRequest()->getMethod(), 'uri' => $e->getRequest()->getUri()]];
 }
开发者ID:wnowicki,项目名称:generic,代码行数:9,代码来源:AbstractApiClient.php

示例11: __construct

 public function __construct(\GuzzleHttp\Exception\RequestException $exception)
 {
     parent::__construct($exception->getMessage(), $exception->getRequest(), $exception->getResponse(), $exception->getPrevious(), $exception->getHandlerContext());
 }
开发者ID:keika299,项目名称:chap,代码行数:4,代码来源:RequestException.php

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

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

示例14: assignExceptions

 /**
  * Method will elaborate on RequestException.
  *
  * @param RequestException $e
  *
  * @throws SalesforceException
  * @throws TokenExpiredException
  */
 private function assignExceptions(RequestException $e)
 {
     if ($e->hasResponse() && $e->getResponse()->getStatusCode() == '401') {
         throw new TokenExpiredException(sprintf('Salesforce token has expired'));
     } elseif ($e->hasResponse()) {
         throw new SalesforceException(sprintf('Salesforce response error: %s', $e->getResponse()));
     } else {
         throw new SalesforceException(sprintf('Invalid request: %s', $e->getRequest()));
     }
 }
开发者ID:DiegoBelatrix,项目名称:forrest,代码行数:18,代码来源:Client.php


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