protected function ExceptionController::decodeException

This method is a temporary port of _drupal_decode_exception().

@todo This should get refactored. FlattenException could use some improvement as well.

Return value

array

1 call to ExceptionController::decodeException()
ExceptionController::on500Html in drupal/core/lib/Drupal/Core/ExceptionController.php
Processes a generic exception into an HTTP 500 response.

File

drupal/core/lib/Drupal/Core/ExceptionController.php, line 332
Definition of Drupal\Core\ExceptionController.

Class

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

Namespace

Drupal\Core

Code

protected function decodeException(FlattenException $exception) {
  $message = $exception
    ->getMessage();
  $backtrace = $exception
    ->getTrace();

  // This value is missing from the stack for some reason in the
  // FlattenException version of the backtrace.
  $backtrace[0]['line'] = $exception
    ->getLine();

  // For database errors, we try to return the initial caller,
  // skipping internal functions of the database layer.
  if (strpos($exception
    ->getClass(), 'DatabaseExceptionWrapper') !== FALSE) {

    // A DatabaseExceptionWrapper exception is actually just a courier for
    // the original PDOException.  It's the stack trace from that exception
    // that we care about.
    $backtrace = $exception
      ->getPrevious()
      ->getTrace();
    $backtrace[0]['line'] = $exception
      ->getLine();

    // The first element in the stack is the call, the second element gives us the caller.
    // We skip calls that occurred in one of the classes of the database layer
    // or in one of its global functions.
    $db_functions = array(
      'db_query',
      'db_query_range',
    );
    while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && (strpos($caller['namespace'], 'Drupal\\Core\\Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions)) {

      // We remove that call.
      array_shift($backtrace);
    }
  }
  $caller = $this
    ->getLastCaller($backtrace);
  return array(
    '%type' => $exception
      ->getClass(),
    // The standard PHP exception handler considers that the exception message
    // is plain-text. We mimick this behavior here.
    '!message' => check_plain($message),
    '%function' => $caller['function'],
    '%file' => $caller['file'],
    '%line' => $caller['line'],
    'severity_level' => WATCHDOG_ERROR,
  );
}