eZ\Bundle\EzPublishCoreBundle\EventListener\ExceptionListener::onKernelException PHP Method

onKernelException() public method

public onKernelException ( GetResponseForExceptionEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        if ($exception instanceof NotFoundException) {
            $event->setException(new NotFoundHttpException($this->getTranslatedMessage($exception), $exception));
        } elseif ($exception instanceof UnauthorizedException) {
            $event->setException(new AccessDeniedException($this->getTranslatedMessage($exception), $exception));
        } elseif ($exception instanceof BadStateException || $exception instanceof InvalidArgumentException) {
            $event->setException(new BadRequestHttpException($this->getTranslatedMessage($exception), $exception));
        } elseif ($exception instanceof Translatable) {
            $event->setException(new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, get_class($exception) . ': ' . $this->getTranslatedMessage($exception), $exception));
        }
    }

Usage Example

 public function testUntouchedException()
 {
     $exception = new \RuntimeException('foo');
     $event = $this->generateExceptionEvent($exception);
     $this->translator->expects($this->never())->method('trans');
     $this->listener->onKernelException($event);
     self::assertSame($exception, $event->getException());
 }