Unify the handling of detailed exception messages

This commit is contained in:
Samuel Georges 2014-12-16 12:21:55 +11:00
parent 8f2f9fd07d
commit d3000ca51a
3 changed files with 30 additions and 25 deletions

View File

@ -418,14 +418,8 @@ class Controller extends Extendable
500
);
}
catch (ApplicationException $ex) {
return Response::make($ex->getMessage(), 500);
}
catch (Exception $ex) {
return Response::make(
sprintf('"%s" on line %s of %s', $ex->getMessage(), $ex->getLine(), $ex->getFile()),
500
);
return Response::make(ApplicationException::getDetailedMessage($ex));
}
}
@ -527,8 +521,9 @@ class Controller extends Extendable
*/
public function handleError($exception)
{
$this->fatalError = $exception->getMessage();
$this->vars['fatalError'] = $exception->getMessage();
$errorMessage = ApplicationException::getDetailedMessage($exception);
$this->fatalError = $errorMessage;
$this->vars['fatalError'] = $errorMessage;
}
//

View File

@ -513,23 +513,8 @@ class Controller extends BaseController
$responseContents['X_OCTOBER_ERROR_MESSAGE'] = $ex->getMessage();
return Response::make($responseContents, 406);
}
catch (ApplicationException $ex) {
return Response::make($ex->getMessage(), 500);
}
catch (Exception $ex) {
/*
* Display a more detailed error if debug mode is activated.
*/
if (Config::get('app.debug', false)) {
return Response::make(sprintf(
'"%s" on line %s of %s',
$ex->getMessage(),
$ex->getLine(),
$ex->getFile()
), 500);
}
return Response::make($ex->getMessage(), 500);
return Response::make(ApplicationException::getDetailedMessage($ex), 500);
}
}

View File

@ -2,7 +2,9 @@
use URL;
use File;
use Config;
use Exception;
use System\Classes\ApplicationException;
/**
* The base exception class.
@ -67,6 +69,29 @@ class ExceptionBase extends Exception
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