Check if a response was received
public hasResponse ( ) : boolean | ||
Результат | boolean |
/** * 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); }
private function manejar_excepcion_request(RequestException $e) { $msg = $e->getRequest() . "\n"; if ($e->hasResponse()) { $msg .= $e->getResponse() . "\n"; } throw new toba_error($msg); }
/** * @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(); } }
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()); }
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()); }
/** * 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; }
/** * 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); } }
/** * 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; }
/** * @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); }
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); }
/** * 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); }