public function ExceptionController::on500Html

Processes a generic exception into an HTTP 500 response.

Parameters

Symfony\Component\HttpKernel\Exception\FlattenException $exception: Metadata about the exception that was thrown.

Symfony\Component\HttpFoundation\Request $request: The request object that triggered this exception.

File

drupal/core/lib/Drupal/Core/Controller/ExceptionController.php, line 210
Contains \Drupal\Core\Controller\ExceptionController.

Class

ExceptionController
This controller handles HTTP errors generated by the routing system.

Namespace

Drupal\Core\Controller

Code

public function on500Html(FlattenException $exception, Request $request) {
  $error = $this
    ->decodeException($exception);

  // Because the kernel doesn't run until full bootstrap, we know that
  // most subsystems are already initialized.
  $headers = array();

  // When running inside the testing framework, we relay the errors
  // to the tested site by the way of HTTP headers.
  $test_info =& $GLOBALS['drupal_test_info'];
  if (!empty($test_info['in_child_site']) && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {

    // $number does not use drupal_static as it should not be reset
    // as it uniquely identifies each PHP error.
    static $number = 0;
    $assertion = array(
      $error['!message'],
      $error['%type'],
      array(
        'function' => $error['%function'],
        'file' => $error['%file'],
        'line' => $error['%line'],
      ),
    );
    $headers['X-Drupal-Assertion-' . $number] = rawurlencode(serialize($assertion));
    $number++;
  }
  watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);

  // Display the message if the current error reporting level allows this type
  // of message to be displayed, and unconditionnaly in update.php.
  if (error_displayable($error)) {
    $class = 'error';

    // If error type is 'User notice' then treat it as debug information
    // instead of an error message, see dd().
    if ($error['%type'] == 'User notice') {
      $error['%type'] = 'Debug';
      $class = 'status';
    }
    drupal_set_message(t('%type: !message in %function (line %line of %file).', $error), $class);
  }
  drupal_set_title(t('Error'));

  // We fallback to a maintenance page at this point, because the page
  // generation itself can generate errors.
  $output = theme('maintenance_page', array(
    'content' => t('The website has encountered an error. Please try again later.'),
  ));
  $response = new Response($output, 500);
  $response
    ->setStatusCode(500, '500 Service unavailable (with message)');
  return $response;
}