public function ExceptionHandler::createResponse

Creates the error Response associated with the given Exception.

Parameters

\Exception|FlattenException $exception An \Exception instance:

Return value

Response A Response instance

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php, line 74

Class

ExceptionHandler
ExceptionHandler converts an exception to a Response object.

Namespace

Symfony\Component\HttpKernel\Debug

Code

public function createResponse($exception) {
  $content = '';
  $title = '';
  try {
    if (!$exception instanceof FlattenException) {
      $exception = FlattenException::create($exception);
    }
    switch ($exception
      ->getStatusCode()) {
      case 404:
        $title = 'Sorry, the page you are looking for could not be found.';
        break;
      default:
        $title = 'Whoops, looks like something went wrong.';
    }
    if ($this->debug) {
      $content = $this
        ->getContent($exception);
    }
  } catch (\Exception $e) {

    // something nasty happened and we cannot throw an exception here anymore
    if ($this->debug) {
      $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception
        ->getMessage());
    }
    else {
      $title = 'Whoops, looks like something went wrong.';
    }
  }
  return new Response($this
    ->decorate($content, $title), $exception
    ->getStatusCode(), $exception
    ->getHeaders());
}