本文整理汇总了PHP中Symfony\Component\Console\Event\ConsoleExceptionEvent::setException方法的典型用法代码示例。如果您正苦于以下问题:PHP ConsoleExceptionEvent::setException方法的具体用法?PHP ConsoleExceptionEvent::setException怎么用?PHP ConsoleExceptionEvent::setException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Event\ConsoleExceptionEvent
的用法示例。
在下文中一共展示了ConsoleExceptionEvent::setException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onException
/**
* React to any console exceptions.
*
* @param ConsoleExceptionEvent $event
*/
public function onException(ConsoleExceptionEvent $event)
{
$exception = $event->getException();
// Replace Guzzle connect exceptions with a friendlier message. This
// also prevents the user from seeing two exceptions (one direct from
// Guzzle, one from RingPHP).
if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
$request = $exception->getRequest();
$event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nRequest URL: " . $request->getUrl() . " \nPlease check your Internet connection"));
$event->stopPropagation();
}
// Handle Guzzle client exceptions, i.e. HTTP 4xx errors.
if ($exception instanceof ClientException && ($response = $exception->getResponse())) {
$request = $exception->getRequest();
try {
$response->getBody()->seek(0);
$json = $response->json();
} catch (ParseException $e) {
$json = [];
}
// Create a friendlier message for the OAuth2 "Invalid refresh token"
// error.
if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
$event->setException(new LoginRequiredException("Invalid refresh token: please log in again." . " \nRequest URL: " . $request->getUrl()));
$event->stopPropagation();
} elseif ($response->getStatusCode() === 401) {
$event->setException(new LoginRequiredException("Unauthorized: please log in again." . " \nRequest URL: " . $request->getUrl()));
$event->stopPropagation();
}
}
}
示例2: onException
/**
* React to any console exceptions.
*
* @param ConsoleExceptionEvent $event
*/
public function onException(ConsoleExceptionEvent $event)
{
$exception = $event->getException();
// Replace Guzzle connect exceptions with a friendlier message. This
// also prevents the user from seeing two exceptions (one direct from
// Guzzle, one from RingPHP).
if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
$request = $exception->getRequest();
$event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nPlease check your Internet connection.", $request));
$event->stopPropagation();
}
// Handle Guzzle client exceptions, i.e. HTTP 4xx errors.
if ($exception instanceof ClientException && ($response = $exception->getResponse())) {
$request = $exception->getRequest();
try {
$response->getBody()->seek(0);
$json = $response->json();
} catch (ParseException $e) {
$json = [];
}
// Create a friendlier message for the OAuth2 "Invalid refresh token"
// error.
if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
$event->setException(new LoginRequiredException("Invalid refresh token: please log in again.", $request));
$event->stopPropagation();
} elseif ($response->getStatusCode() === 401) {
$event->setException(new LoginRequiredException("Unauthorized: please log in again.", $request));
$event->stopPropagation();
} elseif ($response->getStatusCode() === 403) {
$event->setException(new PermissionDeniedException("Permission denied. Check your project or environment permissions.", $request));
$event->stopPropagation();
}
}
// When an environment is found to be in the wrong state, perhaps our
// cache is old - we should invalidate it.
if ($exception instanceof EnvironmentStateException) {
$command = $event->getCommand();
if ($command instanceof PlatformCommand) {
$command->clearEnvironmentsCache();
}
}
}
示例3: onException
/**
* React to any console exceptions.
*
* @param ConsoleExceptionEvent $event
*/
public function onException(ConsoleExceptionEvent $event)
{
$exception = $event->getException();
// Replace Guzzle connect exceptions with a friendlier message. This
// also prevents the user from seeing two exceptions (one direct from
// Guzzle, one from RingPHP).
if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
$request = $exception->getRequest();
$event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nPlease check your Internet connection.", $request));
$event->stopPropagation();
}
// Handle Guzzle exceptions, i.e. HTTP 4xx or 5xx errors.
if (($exception instanceof ClientException || $exception instanceof ServerException) && ($response = $exception->getResponse())) {
$request = $exception->getRequest();
$response->getBody()->seek(0);
$json = (array) json_decode($response->getBody()->getContents(), true);
// Create a friendlier message for the OAuth2 "Invalid refresh token"
// error.
$loginCommand = sprintf('%s login', $this->config->get('application.executable'));
if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
$event->setException(new LoginRequiredException("Invalid refresh token. \nPlease log in again by running: {$loginCommand}", $request, $response));
$event->stopPropagation();
} elseif ($response->getStatusCode() === 401) {
$event->setException(new LoginRequiredException("Unauthorized. \nPlease log in again by running: {$loginCommand}", $request, $response));
$event->stopPropagation();
} elseif ($response->getStatusCode() === 403) {
$event->setException(new PermissionDeniedException("Permission denied. Check your project or environment permissions.", $request, $response));
$event->stopPropagation();
} else {
$event->setException(new HttpException(null, $request, $response));
$event->stopPropagation();
}
}
// When an environment is found to be in the wrong state, perhaps our
// cache is old - we should invalidate it.
if ($exception instanceof EnvironmentStateException) {
$api = new Api();
$api->clearEnvironmentsCache($exception->getEnvironment()->project);
}
}
示例4: on_exception
/**
* This listener is run when the ConsoleEvents::EXCEPTION event is triggered.
* It translate the exception message. If din debug mode the original exception is embedded.
*
* @param ConsoleExceptionEvent $event
*/
public function on_exception(ConsoleExceptionEvent $event)
{
$original_exception = $event->getException();
if ($original_exception instanceof exception_interface) {
$parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters());
$message = call_user_func_array(array($this->language, 'lang'), $parameters);
if ($this->debug) {
$exception = new \RuntimeException($message, $original_exception->getCode(), $original_exception);
} else {
$exception = new \RuntimeException($message, $original_exception->getCode());
}
$event->setException($exception);
}
}