function DefaultExceptionSubscriber::onException

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/src/EventSubscriber/DefaultExceptionSubscriber.php \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::onException()
  2. 10 core/modules/jsonapi/src/EventSubscriber/DefaultExceptionSubscriber.php \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::onException()
  3. 11.x core/modules/jsonapi/src/EventSubscriber/DefaultExceptionSubscriber.php \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::onException()

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\EventSubscriber

Code

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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.