示例#1
0
 public function onKernelException(ExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = $exception->getMessage();
     if ($exception instanceof HttpNotFoundException) {
         return $this->logger->error($message);
     }
     if ($exception instanceof RouteNotFoundException) {
         return $this->logger->error($message);
     }
     if ($exception instanceof MethodNotAllowedException) {
         return $this->logger->error($message);
     }
     $this->logger->critical($message);
 }
示例#2
0
 public function testStopExceptionEvent()
 {
     $request = new Request('GET', '/home', 'HTTP', '1.1');
     $response = Response::createFromRequest($request, '', 200);
     $exception = new \Exception();
     $event = new ExceptionEvent($exception, $request);
     $this->assertSame($exception, $event->getException());
     $this->assertSame($request, $event->getRequest());
     $this->assertNull($event->getResponse());
     $this->assertFalse($event->hasResponse());
     $this->assertFalse($event->isStopped());
     $event->setResponse($response);
     $this->assertTrue($event->hasResponse());
     $this->assertSame($response, $event->getResponse());
     $this->assertTrue($event->isStopped());
 }
示例#3
0
 public function onKernelException(ExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     $vars = ['exception' => $exception, 'request' => $request, 'environment' => $this->environment, 'debug' => $this->debug];
     if ($exception instanceof RouteNotFoundException) {
         $event->setResponse($this->render('errors/404.twig', $vars, Response::HTTP_NOT_FOUND));
         return;
     }
     if ($exception instanceof HttpNotFoundException) {
         $event->setResponse($this->render('errors/404.twig', $vars, Response::HTTP_NOT_FOUND));
         return;
     }
     if ($exception instanceof MethodNotAllowedException) {
         $event->setResponse($this->render('errors/405.twig', $vars, Response::HTTP_METHOD_NOT_ALLOWED));
         return;
     }
     $event->setResponse($this->render('errors/500.twig', $vars));
 }