當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。