From 237d97d87a18fa8eced1d88d9bc5aefeded3ee8d Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Mon, 16 Feb 2015 21:17:03 +1100 Subject: [PATCH] Overhaul exceptions --- src/Exception/ErrorHandler.php | 43 ++++++++++++++++++++++++++-- src/Exception/ExceptionBase.php | 24 ---------------- src/Exception/SystemException.php | 7 ----- src/Foundation/Exception/Handler.php | 17 +++++------ 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/Exception/ErrorHandler.php b/src/Exception/ErrorHandler.php index 2890e3f1a..5d2f8a13e 100644 --- a/src/Exception/ErrorHandler.php +++ b/src/Exception/ErrorHandler.php @@ -1,8 +1,11 @@ getMessage(), $httpCode); + return static::getDetailedMessage($proposedException); } + $this->beforeHandleError($proposedException); + // Clear the output buffer while (ob_get_level()) { ob_end_clean(); @@ -74,7 +79,7 @@ public function handleException(\Exception $proposedException, $httpCode = 500) * @param Exception $exception The mask exception. * @return void */ - public static function applyMask(\Exception $exception) + public static function applyMask(Exception $exception) { if (static::$activeMask !== null) { array_push(static::$maskLayers, static::$activeMask); @@ -97,10 +102,42 @@ public static function removeMask() } } + /** + * Returns a more descriptive error message if application + * debug mode is turned on. + * @param Exception $exception + * @return string + */ + public static function getDetailedMessage($exception) + { + /* + * Application Exceptions never display a detailed error + */ + if (!($exception instanceof ApplicationException) && Config::get('app.debug', false)) { + return sprintf('"%s" on line %s of %s', + $exception->getMessage(), + $exception->getLine(), + $exception->getFile() + ); + } + else { + return $exception->getMessage(); + } + } + // // Overrides // + /** + * We are about to display an error page to the user, + * provide an opportunity to handle extra functions. + * @return void + */ + public function beforeHandleError($exception) + { + } + /** * Check if using a custom error page, if so return the contents. * Return NULL if a custom error is not set up. diff --git a/src/Exception/ExceptionBase.php b/src/Exception/ExceptionBase.php index 8cc676f06..9dfd43ec6 100644 --- a/src/Exception/ExceptionBase.php +++ b/src/Exception/ExceptionBase.php @@ -2,7 +2,6 @@ use URL; use File; -use Config; use Exception; /** @@ -67,29 +66,6 @@ public function __construct($message = "", $code = 0, Exception $previous = null parent::__construct($message, $code, $previous); } - /** - * Returns a more descriptive error message if application - * debug mode is turned on. - * @param Exception $exception - * @return string - */ - public static function getDetailedMessage($exception) - { - /* - * Application Exceptions never display a detailed error - */ - if (!($exception instanceof ApplicationException) && Config::get('app.debug', false)) { - return sprintf('"%s" on line %s of %s', - $exception->getMessage(), - $exception->getLine(), - $exception->getFile() - ); - } - else { - return $exception->getMessage(); - } - } - /** * Returns the class name of the called Exception. * @return string diff --git a/src/Exception/SystemException.php b/src/Exception/SystemException.php index 209c02278..9dfa049f1 100644 --- a/src/Exception/SystemException.php +++ b/src/Exception/SystemException.php @@ -15,12 +15,5 @@ class SystemException extends ExceptionBase public function __construct($message = "", $code = 0, \Exception $previous = null) { parent::__construct($message, $code, $previous); - - /* - * Log the exception - */ - if (!App::runningUnitTests()) { - Log::error($this); - } } } diff --git a/src/Foundation/Exception/Handler.php b/src/Foundation/Exception/Handler.php index 780824f66..5648a5390 100644 --- a/src/Foundation/Exception/Handler.php +++ b/src/Foundation/Exception/Handler.php @@ -1,5 +1,6 @@ shouldntReport($e)) + return; + + Log::error($e); } /** @@ -45,12 +51,7 @@ public function render($request, Exception $e) return Response::make($event, $statusCode); } - if ($this->isHttpException($e)) { - return $this->renderHttpException($e); - } - else { - return parent::render($request, $e); - } + return parent::render($request, $e); } /**