mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Unify the handling of detailed exception messages
This commit is contained in:
parent
8f2f9fd07d
commit
d3000ca51a
@ -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;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user