You are here

public function DefaultExceptionSubscriber::onException in JSON:API 8.2

Same name and namespace in other branches
  1. 8 src/EventSubscriber/DefaultExceptionSubscriber.php \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::onException()

Handles errors for this subscriber.

Parameters

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

Overrides HttpExceptionSubscriberBase::onException

File

src/EventSubscriber/DefaultExceptionSubscriber.php, line 43

Class

DefaultExceptionSubscriber
Serializes exceptions in compliance with the JSON:API specification.

Namespace

Drupal\jsonapi\EventSubscriber

Code

public function onException(GetResponseForExceptionEvent $event) {
  if (!$this
    ->isJsonApiExceptionEvent($event)) {
    return;
  }
  if (($exception = $event
    ->getException()) && !$exception instanceof HttpException) {
    $exception = new HttpException(500, $exception
      ->getMessage(), $exception);
    $event
      ->setException($exception);
  }
  $this
    ->setEventResponse($event, $exception
    ->getStatusCode());
}