DefaultExceptionSubscriber::onJson

protected DefaultExceptionSubscriber::onJson(GetResponseForExceptionEvent $event)

Handles any exception as a generic error page for JSON.

@todo This should probably check the error reporting level.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The event to process.

File

core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php, line 143

Class

DefaultExceptionSubscriber
Last-chance handler for exceptions.

Namespace

Drupal\Core\EventSubscriber

Code

protected function onJson(GetResponseForExceptionEvent $event) {
  $exception = $event->getException();
  $error = Error::decodeException($exception);

  // Display the message if the current error reporting level allows this type
  // of message to be displayed,
  $data = NULL;
  if (error_displayable($error) && $message = $exception->getMessage()) {
    $data = ['message' => sprintf('A fatal error occurred: %s', $message)];
  }

  $response = new JsonResponse($data, Response::HTTP_INTERNAL_SERVER_ERROR);
  if ($exception instanceof HttpExceptionInterface) {
    $response->setStatusCode($exception->getStatusCode());
    $response->headers->add($exception->getHeaders());
  }

  $event->setResponse($response);
}
doc_Drupal
2016-10-29 09:01:41
Comments
Leave a Comment

Please login to continue.