/**
  * @dataProvider provider
  */
 public function testHandleWithLogger($event, $event2)
 {
     $logger = new TestLogger();
     $l = new ExceptionListener('foo', $logger);
     $l->onCoreException($event);
     $this->assertEquals(new Response('foo'), $event->getResponse());
     try {
         $l->onCoreException($event2);
     } catch (\Exception $e) {
         $this->assertSame('foo', $e->getMessage());
     }
     $this->assertEquals(3, $logger->countErrors());
     $this->assertEquals(3, count($logger->getLogs('crit')));
 }
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $request = $event->getRequest();
     if (!in_array($request->getRequestFormat(), array('soap', 'xml'))) {
         return;
     } elseif ('xml' === $request->getRequestFormat() && '_webservice_call' !== $request->attributes->get('_route')) {
         return;
     }
     $attributes = $request->attributes;
     if (!($webservice = $attributes->get('webservice'))) {
         return;
     }
     if (!$this->container->has(sprintf('besimple.soap.context.%s', $webservice))) {
         return;
     }
     // hack to retrieve the current WebService name in the controller
     $request->query->set('_besimple_soap_webservice', $webservice);
     $exception = $event->getException();
     if ($exception instanceof \SoapFault) {
         $request->query->set('_besimple_soap_fault', $exception);
     }
     parent::onKernelException($event);
 }
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $request = $event->getRequest();
     if (empty($this->formats[$request->getRequestFormat()]) && empty($this->formats[$request->getContentType()])) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     if ($exception instanceof AccessDeniedException) {
         $exception = new AccessDeniedHttpException('You do not have the necessary permissions', $exception);
         $event->setException($exception);
         parent::onKernelException($event);
     } elseif ($exception instanceof AuthenticationException) {
         if ($this->challenge) {
             $exception = new UnauthorizedHttpException($this->challenge, 'You are not authenticated', $exception);
         } else {
             $exception = new HttpException(401, 'You are not authenticated', $exception);
         }
         $event->setException($exception);
         parent::onKernelException($event);
     }
     $handling = false;
 }
 /**
  * @param GetResponseForExceptionEvent $event
  * @return bool|void
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     if ($exception instanceof AccessDeniedHttpException) {
         if (StringUtils::startsWith($exception->getMessage(), 'Expression "has_role(\'ROLE_')) {
             $message = 'Bu alana erişebilmek için kullanıcı girişi yapılmalıdır';
             $statusCode = 401;
         } else {
             $message = $exception->getMessage();
             $statusCode = $exception->getStatusCode();
         }
         $exception = new HttpException($statusCode, $message, $exception);
         $event->setException($exception);
         parent::onKernelException($event);
     } elseif ($exception instanceof InsufficientAuthenticationException) {
         $exception = new AccessDeniedHttpException('Bu alana erişebilmek için geçerli bir kullanıcı kimliği belirtilmelidir', $exception);
         $event->setException($exception);
         parent::onKernelException($event);
     }
     $handling = false;
     return false;
 }
 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // Normalize exceptions with hydra errors only for resources
     if (!$event->getRequest()->attributes->has('_resource_type')) {
         return;
     }
     parent::onKernelException($event);
 }
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->headers->has('X-PJAX')) {
         return;
     }
     parent::onKernelException($event);
 }
Example #7
0
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $request = $event->getRequest();
     // Normalize exceptions only for routes managed by API Platform
     if ('html' === $request->getRequestFormat(null) || !$request->attributes->has('_api_resource_class') && !$request->attributes->has('_api_respond')) {
         return;
     }
     parent::onKernelException($event);
 }
 protected function duplicateRequest(\Exception $exception, Request $request)
 {
     $request = parent::duplicateRequest($exception, $request);
     if ($request->attributes->has('exception')) {
         $flattenException = $request->attributes->get('exception');
         $this->recorder->addExceptionAlias($exception, $flattenException);
     }
     return $request;
 }
Example #9
0
 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     // Check for exceptions we don't want to handle
     if ($exception instanceof AuthenticationException || $exception instanceof AccessDeniedException || $exception instanceof LogoutException) {
         return;
     }
     // Let the HttpKernel listener handle the rest
     parent::onKernelException($event);
 }
 /**
  * {@inheritdoc}
  */
 protected function duplicateRequest(\Exception $exception, Request $request)
 {
     if (!$this->isLegacySymfony()) {
         $request = parent::duplicateRequest($exception, $request);
     } else {
         $request = $this->legacyDuplicateRequest($request);
     }
     $request->attributes->set('exception', FlattenException::create($exception));
     return $request;
 }
Example #11
0
 public function testSubRequestFormat()
 {
     $listener = new ExceptionListener('foo', $this->getMock('Psr\\Log\\LoggerInterface'));
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
         return new Response($request->getRequestFormat());
     }));
     $request = Request::create('/');
     $request->setRequestFormat('xml');
     $event = new GetResponseForExceptionEvent($kernel, $request, 'foo', new \Exception('foo'));
     $listener->onKernelException($event);
     $response = $event->getResponse();
     $this->assertEquals('xml', $response->getContent());
 }
 /**
  * @param GetResponseForExceptionEvent $event
  *
  * @return void
  * @author Michaël VEROUX
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof AccessDeniedException) {
         $exception = null;
         try {
             parent::onKernelException($event);
         } catch (\Exception $e) {
             $exception = $e;
         }
         if (!$exception instanceof HttpExceptionInterface && !$event->getException() instanceof HttpExceptionInterface && 'prod' === $this->mode) {
             $this->loggerDb->error($event->getException()->getMessage(), array('exception' => $event->getException()));
             if ($this->flashBag) {
                 if (null === $this->lastError->getId()) {
                     $this->flashBag->add('error', 'Une erreur est survenue');
                 } else {
                     $this->flashBag->add('error', sprintf('Une erreur est survenue #%s', $this->lastError->getId()));
                 }
             }
         }
     }
 }
 /**
  * @param TokenStorageInterface $tokenStorage
  * @param LoggerInterface       $logger
  */
 public function __construct(TokenStorageInterface $tokenStorage, LoggerInterface $logger = null)
 {
     parent::__construct('clastic.backoffice.controller.exception:showAction', $logger);
 }