本文整理汇总了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);
}
示例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);
}
示例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();
}
}
示例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());
}
示例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());
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}