protected function 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\EventSubscriberCode
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); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!EventSubscriber!DefaultExceptionSubscriber.php/function/DefaultExceptionSubscriber::onJson/8.1.x