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


PHP RequestException::hasResponse方法代码示例

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


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

示例3: __construct

 /**
  * @param ResponseInterface|null $response
  * @param RequestException|null $exception
  */
 public function __construct(ResponseInterface $response = null, RequestException $exception = null)
 {
     $this->response = $response;
     $this->exception = $exception;
     if (null === $response && ($exception && $exception->hasResponse())) {
         $this->response = $exception->getResponse();
     }
 }
开发者ID:thisdata,项目名称:thisdata-php,代码行数:12,代码来源:Event.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: __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

示例6: getPrettyErrorMessage

 /**
  * Gives human readable error message
  * @param RequestException $requestException
  * @return string
  */
 protected function getPrettyErrorMessage(RequestException $requestException)
 {
     if (!$requestException->hasResponse()) {
         throw $requestException;
     }
     $errorMessage = '';
     $response = json_decode($requestException->getResponse()->getBody()->getContents(), true);
     if (isset($response['message'])) {
         $errorMessage .= $response['message'];
         $errorMessage .= $this->getDetailedErrorMessage($response);
     }
     if (isset($response['error_description'])) {
         $errorMessage .= $response['error_description'];
     }
     if (isset($response['error'])) {
         $errorMessage .= ' [' . $response['error'] . ']';
     }
     if (isset($response['code'])) {
         $errorMessage .= ' code: ' . $response['code'];
     }
     return $errorMessage;
 }
开发者ID:shopiolabs,项目名称:shopioapi,代码行数:27,代码来源:AbstractShopioClient.php

示例7: 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('Salesforce token has expired', $e);
     } elseif ($e->hasResponse()) {
         throw new SalesforceException('Salesforce response error', $e);
     } else {
         throw new SalesforceException('Invalid request: %s', $e);
     }
 }
开发者ID:cmpas2,项目名称:ayforrest,代码行数:18,代码来源:Client.php

示例8: handleException

 /**
  * Handles exceptions for requests, specifically unauthorized access.
  *
  * @param RequestException $e
  * @throws CachetAuthenticationException
  */
 private function handleException(RequestException $e)
 {
     if ($e->hasResponse()) {
         // Unauthorized
         if ($e->getResponse()->getStatusCode() == 401) {
             throw new CachetAuthenticationException();
         }
     }
     // Push it up the stack.
     throw $e;
 }
开发者ID:nikkiii,项目名称:laravel-cachet,代码行数:17,代码来源:CachetConnection.php

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

示例10: handleRequestException

 private function handleRequestException(RequestException $ex)
 {
     if ($ex->hasResponse()) {
         $response = $ex->getResponse();
         $code = $response->getStatusCode();
         $reason = $response->getReasonPhrase();
         $msg = $this->getSolrErrorMessage($response);
         if ($msg !== null) {
             throw new SolrException("Solr returned HTTP {$code} {$reason}: {$msg}", 0, $ex);
         } else {
             throw new SolrException("Solr returned HTTP {$code} {$reason}", 0, $ex);
         }
     }
     throw new SolrException("Solr query failed", 0, $ex);
 }
开发者ID:opendi,项目名称:solrclient,代码行数:15,代码来源:Client.php

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