public function HttpExceptionSubscriberBase::onException in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php \Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase::onException()
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 85 
- Contains \Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase.
Class
- HttpExceptionSubscriberBase
- Utility base class for exception subscribers.
Namespace
Drupal\Core\EventSubscriberCode
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);
    }
  }
}