Skip to content

Instantly share code, notes, and snippets.

@everzet
Last active February 27, 2017 12:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everzet/8422447 to your computer and use it in GitHub Desktop.
Save everzet/8422447 to your computer and use it in GitHub Desktop.
Rethrow non-HTTP exceptions in the test environment (aka functional tester saver)
...
services:
listener.exception_rethrow:
class: App\EventListener\ExceptionRethrowListener
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
<?php
namespace App\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class ExceptionRethrowListener
{
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($exception instanceof HttpExceptionInterface) {
return;
}
throw $exception;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment