public function DefaultExceptionSubscriber::onException in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/EventSubscriber/DefaultExceptionSubscriber.php \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::onException()
- 9 core/modules/jsonapi/src/EventSubscriber/DefaultExceptionSubscriber.php \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::onException()
Handles errors for this subscriber.
Parameters
\Symfony\Component\HttpKernel\Event\ExceptionEvent $event: The event to process.
Overrides HttpExceptionSubscriberBase::onException
File
- core/
modules/ jsonapi/ src/ EventSubscriber/ DefaultExceptionSubscriber.php, line 44
Class
- DefaultExceptionSubscriber
- Serializes exceptions in compliance with the JSON:API specification.
Namespace
Drupal\jsonapi\EventSubscriberCode
public function onException(ExceptionEvent $event) {
if (!$this
->isJsonApiExceptionEvent($event)) {
return;
}
if (($exception = $event
->getThrowable()) && !$exception instanceof HttpException) {
$exception = new HttpException(500, $exception
->getMessage(), $exception);
$event
->setThrowable($exception);
}
$this
->setEventResponse($event, $exception
->getStatusCode());
}