You are here

public function EdgeExceptionSubscriber::onException in Apigee Edge 8

Displays the Edge connection error page.

Parameters

\Symfony\Component\HttpKernel\Event\ExceptionEvent|\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The exception event.

File

src/EventSubscriber/EdgeExceptionSubscriber.php, line 124

Class

EdgeExceptionSubscriber
Handles uncaught ApiExceptions.

Namespace

Drupal\apigee_edge\EventSubscriber

Code

public function onException($event) {
  $exception = $event instanceof ExceptionEvent ? $event
    ->getThrowable() : $event
    ->getException();
  if ($exception instanceof ApiException || $exception
    ->getPrevious() instanceof ApiException) {
    $context = Error::decodeException($exception);
    $this->logger
      ->critical('@message %function (line %line of %file). <pre>@backtrace_string</pre>', $context);
    $controller = $this->classResolver
      ->getInstanceFromDefinition(ErrorPageController::class);
    $content = [
      '#title' => $controller
        ->getPageTitle(),
      'content' => $controller
        ->render(),
    ];
    $routeMatch = new RouteMatch('apigee_edge.error_page', new Route('/api-communication-error'));
    $renderer = $this->classResolver
      ->getInstanceFromDefinition($this->mainContentRenderers['html']);

    /* @var \Symfony\Component\HttpFoundation\Response $response */
    $response = $renderer
      ->renderResponse($content, $event
      ->getRequest(), $routeMatch);
    $response
      ->setStatusCode(503);

    // Display additional debug messages.
    if ($this->configFactory
      ->get('apigee_edge.error_page')
      ->get('error_page_debug_messages')) {
      $this->messenger
        ->addError($exception
        ->getMessage());
    }
    $event
      ->setResponse($response);
  }
}