You are here

protected function DrupalKernel::handleException in Drupal 10

Same name and namespace in other branches
  1. 8 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.

1 call to DrupalKernel::handleException()
DrupalKernel::handle in core/lib/Drupal/Core/DrupalKernel.php

File

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

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;
}