Skip to content

Instantly share code, notes, and snippets.

@bifidokk
Created October 30, 2016 16:56
Show Gist options
  • Select an option

  • Save bifidokk/a88b3f0da53b7fe8f27472b48621c78d to your computer and use it in GitHub Desktop.

Select an option

Save bifidokk/a88b3f0da53b7fe8f27472b48621c78d to your computer and use it in GitHub Desktop.
<?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