Browse Source

[HttpKernel] split ExceptionHandler::handle() in two methods for better re-usability

Fabien Potencier 14 years ago
parent
commit
311d691670
1 changed files with 17 additions and 7 deletions
  1. 17 7
      src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php

+ 17 - 7
src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php

@@ -42,23 +42,33 @@ class ExceptionHandler
     }
 
     /**
-     * Returns a Response for the given Exception.
+     * Sends a Response for the given Exception.
      *
      * @param \Exception $exception An \Exception instance
-     *
-     * @return Response A Response instance
      */
     public function handle(\Exception $exception)
+    {
+        $response = new Response($this->getErrorMessage($exception), 500);
+
+        $response->send();
+    }
+
+    /**
+     * Gets the error message associated with the given Exception.
+     *
+     * @param \Exception $exception An \Exception instance
+     *
+     * @return string An HTML content describing the Exception
+     */
+    public function getErrorMessage(\Exception $exception)
     {
         try {
             $exception = FlattenException::create($exception);
 
-            $response = new Response($this->decorate($exception, $this->getContent($exception)), 500);
-
-            $response->send();
+            return $this->decorate($exception, $this->getContent($exception));
         } catch (\Exception $e) {
             // something nasty happened and we cannot throw an exception here anymore
-            printf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
+            return sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
         }
     }