Преглед на файлове

tweaked behavior of ExceptionListener to display better error messages in case of an exception thrown during the handling of an exception

Fabien Potencier преди 14 години
родител
ревизия
71d5be1d6b
променени са 1 файла, в които са добавени 12 реда и са изтрити 3 реда
  1. 12 3
      src/Symfony/Component/HttpKernel/Debug/ExceptionListener.php

+ 12 - 3
src/Symfony/Component/HttpKernel/Debug/ExceptionListener.php

@@ -48,10 +48,14 @@ class ExceptionListener
 
     public function handle(Event $event)
     {
-        if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
+        static $handling;
+
+        if (true === $handling) {
             return false;
         }
 
+        $handling = true;
+
         $exception = $event->get('exception');
         $request = $event->get('request');
 
@@ -76,16 +80,21 @@ class ExceptionListener
         try {
             $response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
         } catch (\Exception $e) {
+            $message = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage());
             if (null !== $this->logger) {
-                $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
+                $this->logger->err($message);
+            } else {
+                error_log($message);
             }
 
             // re-throw the exception as this is a catch-all
-            throw new \RuntimeException('Exception thrown when handling an exception.', 0, $e);
+            throw $exception;
         }
 
         $event->setReturnValue($response);
 
+        $handling = false;
+
         return true;
     }
 }