public HttpExceptionSubscriberBase::onException(GetResponseForExceptionEvent $event)
Handles errors for this subscriber.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The event to process.
File
- core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php, line 80
Class
- HttpExceptionSubscriberBase
- Utility base class for exception subscribers.
Namespace
Drupal\Core\EventSubscriber
Code
public function onException(GetResponseForExceptionEvent $event) {
$exception = $event->getException();
// Make the exception available for example when rendering a block.
$request = $event->getRequest();
$request->attributes->set('exception', $exception);
$handled_formats = $this->getHandledFormats();
$format = $request->query->get(MainContentViewSubscriber::WRAPPER_FORMAT, $request->getRequestFormat());
if ($exception instanceof HttpExceptionInterface && (empty($handled_formats) || in_array($format, $handled_formats))) {
$method = 'on' . $exception->getStatusCode();
// We want to allow the method to be called and still not set a response
// if it has additional filtering logic to determine when it will apply.
// It is therefore the method's responsibility to set the response on the
// event if appropriate.
if (method_exists($this, $method)) {
$this->$method($event);
}
}
}
Please login to continue.