Last active
February 27, 2017 12:18
-
-
Save everzet/8422447 to your computer and use it in GitHub Desktop.
Rethrow non-HTTP exceptions in the test environment (aka functional tester saver)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
services: | |
listener.exception_rethrow: | |
class: App\EventListener\ExceptionRethrowListener | |
tags: | |
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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