Created
October 30, 2016 16:56
-
-
Save bifidokk/a88b3f0da53b7fe8f27472b48621c78d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| use Symfony\Component\HttpFoundation\Response; | |
| use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | |
| use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | |
| use Symfony\Component\Security\Core\Exception\AuthenticationException; | |
| class ExceptionListener | |
| { | |
| public function onKernelException(GetResponseForExceptionEvent $event) | |
| { | |
| $exception = $event->getException(); | |
| if ($exception instanceof AuthenticationException) { | |
| $event->setResponse(new Response($exception->getMessage(), 403)); | |
| } | |
| if ($exception instanceof AccessDeniedHttpException) { | |
| $event->setResponse(new Response($exception->getMessage(), 401)); | |
| } | |
| //..... | |
| } | |
| } | |
| //..... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment