final class EdgeExceptionSubscriber in Apigee Edge 8
Handles uncaught ApiExceptions.
Redirects the user to the Edge error page if an uncaught SDK-level ApiException event appears in the HttpKernel component.
Hierarchy
- class \Drupal\apigee_edge\EventSubscriber\EdgeExceptionSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of EdgeExceptionSubscriber
1 file declares its use of EdgeExceptionSubscriber
- EdgeExceptionSubscriberTest.php in tests/
src/ Unit/ EventSubscriber/ EdgeExceptionSubscriberTest.php
1 string reference to 'EdgeExceptionSubscriber'
1 service uses EdgeExceptionSubscriber
File
- src/
EventSubscriber/ EdgeExceptionSubscriber.php, line 42
Namespace
Drupal\apigee_edge\EventSubscriberView source
final class EdgeExceptionSubscriber implements EventSubscriberInterface {
/**
* The logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Class Resolver service.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
*/
protected $classResolver;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* The available main content renderer services, keyed per format.
*
* @var array
*/
protected $mainContentRenderers;
/**
* EdgeExceptionSubscriber constructor.
*
* @param \Psr\Log\LoggerInterface $logger
* The logger service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* The class resolver service.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param array $main_content_renderers
* The available main content renderer service IDs, keyed by format.
*/
public function __construct(LoggerInterface $logger, ConfigFactoryInterface $config_factory, MessengerInterface $messenger, ClassResolverInterface $class_resolver, RouteMatchInterface $route_match, array $main_content_renderers) {
$this->logger = $logger;
$this->configFactory = $config_factory;
$this->messenger = $messenger;
$this->classResolver = $class_resolver;
$this->routeMatch = $route_match;
$this->mainContentRenderers = $main_content_renderers;
}
/**
* {@inheritdoc}
*/
protected static function getPriority() {
return 1024;
}
/**
* Displays the Edge connection error page.
*
* @param \Symfony\Component\HttpKernel\Event\ExceptionEvent|\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
* The exception event.
*/
public function onException($event) {
$exception = $event instanceof ExceptionEvent ? $event
->getThrowable() : $event
->getException();
if ($exception instanceof ApiException || $exception
->getPrevious() instanceof ApiException) {
$context = Error::decodeException($exception);
$this->logger
->critical('@message %function (line %line of %file). <pre>@backtrace_string</pre>', $context);
$controller = $this->classResolver
->getInstanceFromDefinition(ErrorPageController::class);
$content = [
'#title' => $controller
->getPageTitle(),
'content' => $controller
->render(),
];
$routeMatch = new RouteMatch('apigee_edge.error_page', new Route('/api-communication-error'));
$renderer = $this->classResolver
->getInstanceFromDefinition($this->mainContentRenderers['html']);
/* @var \Symfony\Component\HttpFoundation\Response $response */
$response = $renderer
->renderResponse($content, $event
->getRequest(), $routeMatch);
$response
->setStatusCode(503);
// Display additional debug messages.
if ($this->configFactory
->get('apigee_edge.error_page')
->get('error_page_debug_messages')) {
$this->messenger
->addError($exception
->getMessage());
}
$event
->setResponse($response);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::EXCEPTION][] = [
'onException',
static::getPriority(),
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EdgeExceptionSubscriber:: |
protected | property | Class Resolver service. | |
EdgeExceptionSubscriber:: |
protected | property | The config factory service. | |
EdgeExceptionSubscriber:: |
protected | property | The logger instance. | |
EdgeExceptionSubscriber:: |
protected | property | The available main content renderer services, keyed per format. | |
EdgeExceptionSubscriber:: |
protected | property | The messenger service. | |
EdgeExceptionSubscriber:: |
protected | property | The current route match. | |
EdgeExceptionSubscriber:: |
protected static | function | ||
EdgeExceptionSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
EdgeExceptionSubscriber:: |
public | function | Displays the Edge connection error page. | |
EdgeExceptionSubscriber:: |
public | function | EdgeExceptionSubscriber constructor. |