本文整理汇总了PHP中Exception::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getResponse方法的具体用法?PHP Exception::getResponse怎么用?PHP Exception::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::getResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factory
public static function factory($name, \Exception $exception)
{
$message = sprintf("%s could not be found. The API returned this HTTP response:\n\n%s", $name, (string) $exception->getResponse());
$e = new self($message);
$e->name = $name;
$e->response = $exception->getResponse();
$e->request = $exception->getRequest();
return $e;
}
示例2: __construct
/**
* Sets up the custom exception and copies over original exception values.
*
* @param Exception $exception - the exception to be wrapped
*/
public function __construct(\Exception $exception)
{
$message = $exception->getMessage();
$code = $exception->getCode();
if ($exception instanceof HttpException) {
$message = $exception->getResponse()->getBody()->__toString();
$this->body = json_decode($message, true);
$code = $exception->getResponse()->getStatusCode();
}
parent::__construct($message, $code, $exception->getPrevious());
}
示例3: BadResponseHandler
/**
* Put an error message corresponding to a bad response in function of the status code in the output
*
* @param Exception $error the exception triggered
*
* @return void
*/
public function BadResponseHandler($error)
{
$statusCode = $error->getResponse()->getStatusCode();
switch ($statusCode) {
case 400:
$this->app->setOutput("Error", "Invalid input.");
break;
case 401:
$this->app->setOutput("Error", "Authentification failed.");
break;
case 403:
$this->app->setOutput("Error", "Operation forbidden.");
break;
case 404:
$this->app->setOutput("Error", "Ressource not found.");
break;
case 500:
$this->app->setOutput("Error", "Internal server error, please contact an administrator.");
break;
case 503:
$this->app->setOutput("Error", "Service unvailable for the moment.");
break;
default:
$this->app->setOutput("Error", "Unknow error, please contact an administrator.");
break;
}
}
示例4: write
/**
* @param array $items
*/
public function write(array $items)
{
//file_put_contents('product_association.json', json_encode($items));
foreach ($items as $item) {
try {
// Send only when association exist
if (count($item[key($item)]) > 0) {
$this->webservice->sendAssociation($item);
}
} catch (\Exception $e) {
$event = new InvalidItemEvent(__CLASS__, $e->getMessage(), array(), ['sku' => array_key_exists('sku', $item) ? $item['sku'] : 'NULL']);
// Logging file
$this->eventDispatcher->dispatch(EventInterface::INVALID_ITEM, $event);
// Loggin Interface
$this->stepExecution->addWarning(__CLASS__, $e->getMessage(), array(), ['sku' => array_key_exists('sku', $item) ? $item['sku'] : 'NULL']);
/** @var ClientErrorResponseException $e */
if ($e->getResponse()->getStatusCode() <= 404) {
$e = new \Exception($e->getResponse()->getReasonPhrase());
$this->stepExecution->addFailureException($e);
$exitStatus = new ExitStatus(ExitStatus::FAILED);
$this->stepExecution->setExitStatus($exitStatus);
}
// Handle next element.
}
$this->stepExecution->incrementSummaryInfo('write');
$this->stepExecution->incrementWriteCount();
}
}
示例5: test_getResponse_returnsResponse_ifResponseDoesExist
/**
* getResponse() should return response if response does exist
*/
public function test_getResponse_returnsResponse_ifResponseDoesExist()
{
$response = new \Jstewmc\Api\Response\Json();
$exception = new Exception();
$exception->setResponse($response);
$this->assertSame($response, $exception->getResponse());
return;
}
示例6: createFromException
/**
* Constructs a new enforced response from the given exception.
*
* Note that it is necessary to traverse the exception chain when searching
* for an enforced response. Otherwise it would be impossible to find an
* exception thrown from within a twig template.
*
* @param \Exception $e
* The exception where the enforced response is to be extracted from.
*
* @return \Drupal\Core\Form\EnforcedResponse|null
* The enforced response or NULL if the exception chain does not contain a
* \Drupal\Core\Form\EnforcedResponseException exception.
*/
public static function createFromException(\Exception $e)
{
while ($e) {
if ($e instanceof EnforcedResponseException) {
return new static($e->getResponse());
}
$e = $e->getPrevious();
}
}
示例7: _logResponseException
protected function _logResponseException(Exception $e)
{
if ($e instanceof \Payin7Payments\Exception\Payin7APIException) {
$response = $e->getResponse();
$code = $response->getStatusCode();
$body = $response->getBody();
$this->_logger->logError("[API SERVER ERROR] Status Code: {$code} | Body: {$body}");
} else {
$this->_logger->logError("[API SERVER ERROR] " . $e->getMessage() . ', Code: ' . $e->getCode());
}
}
示例8: createFromException
/**
* @param \Exception $exception
* @return GuzzleRestException
*/
public static function createFromException(\Exception $exception)
{
if ($exception instanceof BadResponseException && $exception->getResponse()) {
$url = $exception->getRequest() ? (string) $exception->getRequest()->getUrl() : null;
$result = GuzzleRestException::createFromResponse(new GuzzleRestResponse($exception->getResponse(), $url), null, $exception);
} else {
/** @var GuzzleRestException $result */
$result = new static($exception->getMessage(), $exception->getCode(), $exception);
}
return $result;
}
示例9: renderException
/**
* @param \Exception $e
*
* @return array
*/
public static function renderException($e)
{
$click = function ($o, $c = TRUE) {
return Dumper::toHtml($o, array('collapse' => $c));
};
$panel = array();
if ($e instanceof Curl\FailedRequestException) {
$panel['info'] = '<h3>Info</h3>' . $click($e->getInfo(), TRUE);
}
if ($e instanceof Curl\CurlException) {
if ($e->getRequest()) {
$panel['request'] = '<h3>Request</h3>' . $click($e->getRequest(), TRUE);
}
if ($e->getResponse()) {
$panel['response'] = '<h3>Responses</h3>' . static::allResponses($e->getResponse());
}
}
if (!empty($panel)) {
return array('tab' => 'Curl', 'panel' => implode($panel));
}
}
示例10: renderAsRestAPI
public function renderAsRestAPI($request, \Exception $e)
{
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} elseif ($e instanceof AuthorizationException) {
$e = new HttpException(403, $e->getMessage());
} elseif ($e instanceof ValidationException && $e->getResponse()) {
return $e->getResponse();
}
$fe = FlattenException::create($e);
$data = env("APP_DEBUG", false) ? $fe->toArray() : ["message" => "whoops, something wrong."];
return JsonResponse::create($data, 500);
}
示例11: handle
/**
* Captch known exceptions
* @param \Exception $e
* @throws ApiLimitException
* @throws InvalidXmlException
* @throws UnauthorizedException
* @throws \Exception
*/
public function handle(\Exception $e)
{
$response = $e->getResponse();
$statusCode = $response->getStatusCode();
if ($statusCode == 401) {
throw new UnauthorizedException("Authorization failed. Are your public and private key correct?");
} else {
if ($statusCode == 400) {
throw new InvalidXmlException();
} else {
if ($statusCode == 503 || $statusCode == 409) {
throw new ApiLimitException();
}
}
}
$body = $response->getBody(true);
$message = $this->xmlParser->parse($body);
if (isset($message['ErrorCode'])) {
throw new BolException($message['ErrorCode'] . ": " . $message['ErrorMessage']);
}
throw new \Exception("Unknown error occurred. Status code: {$response->getStatusCode()}.");
}
示例12: throwServiceExceptionIfDetected
/**
* Convert an exception to an ServiceException if an AppsForYourDomain
* XML document is contained within the original exception's HTTP
* response. If conversion fails, throw the original error.
*
* @param Exception $e The exception to convert.
* @throws GApps\ServiceException
* @throws mixed
*/
public static function throwServiceExceptionIfDetected($e)
{
// Check to make sure that there actually response!
// This can happen if the connection dies before the request
// completes. (See ZF-5949)
$response = $e->getResponse();
if (!$response) {
throw new App\IOException('No HTTP response received (possible connection failure)');
}
try {
// Check to see if there is an AppsForYourDomainErrors
// datastructure in the response. If so, convert it to
// an exception and throw it.
$error = new GApps\ServiceException();
$error->importFromString($response->getBody());
throw $error;
} catch (App\Exception $e2) {
// Unable to convert the response to a ServiceException,
// most likely because the server didn't return an
// AppsForYourDomainErrors document. Throw the original
// exception.
throw $e;
}
}
示例13: getBluedroneException
/**
* It converts all exceptions to Bluedrone Api Exceptions which are
* in fact Problem objects. The Problem object offers
* more details about the error that occurred.
*
* @param \Exception $e
*
* @return BluedroneException
*/
protected function getBluedroneException(\Exception $e)
{
if ($e instanceof BadResponseException) {
// if it's a 4xx or 5xx error
$statusCode = $e->getResponse()->getStatusCode();
$body = $e->getResponse()->getBody(true);
$jsonBody = json_decode($body, true);
// check to see if the server responded well behaved (with a json object)
if ($jsonBody !== null && count($jsonBody) != 0) {
$bluedroneException = BluedroneException::fromArray($jsonBody);
} else {
// if not, it means we're talking about an unrecoverable server error
$bluedroneException = new BluedroneException('Unrecoverable Server Error', 0, "The server responded with code '{$statusCode}' but did not provide more details about the error.");
}
} elseif ($e instanceof RequestException) {
// if it's a connection error
$bluedroneException = new BluedroneException('Connection Error', 0, $e->getMessage());
} else {
$bluedroneException = new BluedroneException('Exception', 0, $e->getMessage());
}
return $bluedroneException;
}
示例14: handleInternalException
/**
* @param \Exception $ex
*
* @return ResponseInterface|null
*/
private function handleInternalException(\Exception $ex)
{
$response = null;
if ($ex instanceof ResponseAwareExceptionInterface) {
$response = $ex->getResponse();
}
if ($ex instanceof ServerStopExceptionInterface) {
$this->stopServerByException($ex);
}
return $response;
}
示例15: handle_exception
/**
* Set The exception to Bridge_Exception_ActionAuthNeedReconnect
* if exception is instance of Zend_Gdata_App_HttpException and Http code 401
*
* @param Exception $e
* @return Void
*/
public function handle_exception(Exception $e)
{
if ($e instanceof Zend_Gdata_App_HttpException) {
$response = $e->getResponse();
$http_code = $response->getStatus();
if ($http_code == 401) {
$e = new Bridge_Exception_ActionAuthNeedReconnect();
return;
}
$message = $code = "";
switch ($response->getStatus()) {
case 400:
$message = $this->translator->trans("Erreur la requête a été mal formée ou contenait des données valides.");
break;
case 401:
$message = $this->translator->trans("Erreur lors de l'authentification au service Youtube, Veuillez vous déconnecter, puis vous reconnecter.");
break;
case 403:
$message = $this->translator->trans("Erreur lors de l'envoi de la requête. Erreur d'authentification.");
break;
case 404:
$message = $this->translator->trans("Erreur la ressource que vous tentez de modifier n'existe pas.");
break;
case 500:
$message = $this->translator->trans("Erreur YouTube a rencontré une erreur lors du traitement de la requête.");
break;
case 501:
$message = $this->translator->trans("Erreur vous avez essayé d'exécuter une requête non prise en charge par Youtube");
break;
case 503:
$message = $this->translator->trans("Erreur le service Youtube n'est pas accessible pour le moment. Veuillez réessayer plus tard.");
break;
}
if ($error = $this->parse_xml_error($response->getBody())) {
$code = $error['code'];
if ($code == "too_many_recent_calls") {
$this->block_api(10 * 60 * 60);
$e = new Bridge_Exception_ApiDisabled($this->get_api_manager());
return;
}
$reason = '';
switch ($code) {
case "required":
$reason = $this->translator->trans("A required field is missing or has an empty value");
break;
case "deprecated":
$reason = $this->translator->trans("A value has been deprecated and is no longer valid");
break;
case "invalid_format":
$reason = $this->translator->trans("A value does not match an expected format");
break;
case "invalid_character":
$reason = $this->translator->trans("A field value contains an invalid character");
break;
case "too_long":
$reason = $this->translator->trans("A value exceeds the maximum allowable length");
break;
case "too_many_recent_calls":
$reason = $this->translator->trans("The Youtube servers have received too many calls from the same caller in a short amount of time.");
break;
case "too_many_entries":
$reason = $this->translator->trans("You are attempting to exceed the storage limit on your account and must delete existing entries before inserting new entries");
break;
case "InvalidToken":
$reason = $this->translator->trans("The authentication token specified in the Authorization header is invalid");
break;
case "TokenExpired":
$reason = $this->translator->trans("The authentication token specified in the Authorization header has expired.");
break;
case "disabled_in_maintenance_mode":
$reason = $this->translator->trans("Current operations cannot be executed because the site is temporarily in maintenance mode. Wait a few minutes and try your request again");
break;
}
$message .= '<br/>' . $reason . '<br/>Youtube said : ' . $error['message'];
}
if ($error == false && $response->getStatus() == 404) {
$message = $this->translator->trans("Service youtube introuvable.");
}
$e = new Exception($message);
}
return;
}