vendor/trikoder/oauth2-bundle/EventListener/ConvertExceptionToResponseListener.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Trikoder\Bundle\OAuth2Bundle\EventListener;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  6. use Trikoder\Bundle\OAuth2Bundle\Security\Exception\InsufficientScopesException;
  7. use Trikoder\Bundle\OAuth2Bundle\Security\Exception\Oauth2AuthenticationFailedException;
  8. /**
  9. * @author Tobias Nyholm <tobias.nyholm@gmail.com>
  10. */
  11. final class ConvertExceptionToResponseListener
  12. {
  13. public function onKernelException(ExceptionEvent $event): void
  14. {
  15. $exception = $event->getThrowable();
  16. if ($exception instanceof InsufficientScopesException || $exception instanceof Oauth2AuthenticationFailedException) {
  17. $event->setResponse(new Response($exception->getMessage(), $exception->getCode()));
  18. }
  19. }
  20. }