Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::handleException()
  2. 9 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::handleException()

Converts an exception into a response.

Parameters

\Exception $e: An exception

\Symfony\Component\HttpFoundation\Request $request: A Request instance

int $type: The type of the request (one of HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST)

Return value

\Symfony\Component\HttpFoundation\Response A Response instance

Throws

\Exception If the passed in exception cannot be turned into a response.

2 calls to DrupalKernel::handleException()
DrupalKernel::handle in core/lib/Drupal/Core/DrupalKernel.php
UpdateKernel::handle in core/lib/Drupal/Core/Update/UpdateKernel.php

File

core/lib/Drupal/Core/DrupalKernel.php, line 769

Class

DrupalKernel
The DrupalKernel class is the core of Drupal itself.

Namespace

Drupal\Core

Code

protected function handleException(\Exception $e, $request, $type) {
  if ($this
    ->shouldRedirectToInstaller($e, $this->container ? $this->container
    ->get('database') : NULL)) {
    return new RedirectResponse($request
      ->getBasePath() . '/core/install.php', 302, [
      'Cache-Control' => 'no-cache',
    ]);
  }
  if ($e instanceof HttpExceptionInterface) {
    $response = new Response($e
      ->getMessage(), $e
      ->getStatusCode());
    $response->headers
      ->add($e
      ->getHeaders());
    return $response;
  }
  throw $e;
}