setEventResponse example


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

  /** * {@inheritdoc} */
  protected function setEventResponse(ExceptionEvent $event$status) {
    /** @var \Symfony\Component\HttpKernel\Exception\HttpException $exception */
    $exception = $event->getThrowable();
    $document = new JsonApiDocumentTopLevel(new ErrorCollection([$exception])new NullIncludedData()new LinkCollection([]));
    if ($event->getRequest()->isMethodCacheable()) {
      $response = new CacheableResourceResponse($document$exception->getStatusCode()$exception->getHeaders());
      
Home | Imprint | This part of the site doesn't use cookies.