Index and Action use Exceptions

Main Web entry point accepts exceptions, and main code in Action
throws them.
This commit is contained in:
Evan Prodromou 2009-02-09 07:15:52 -05:00
parent 9152c0bdc8
commit aa06d760b3
2 changed files with 27 additions and 8 deletions

View File

@ -47,7 +47,11 @@ if (!$user && common_config('site', 'private') &&
$actionfile = INSTALLDIR."/actions/$action.php"; $actionfile = INSTALLDIR."/actions/$action.php";
if (file_exists($actionfile)) { if (!file_exists($actionfile)) {
$cac = new ClientErrorAction();
$cac->handle(array('code' => 404,
'message' => _('Unknown action')));
} else {
include_once $actionfile; include_once $actionfile;
@ -66,9 +70,22 @@ if (file_exists($actionfile)) {
} }
$config['db']['database'] = $mirror; $config['db']['database'] = $mirror;
} }
if (call_user_func(array($action_obj, 'prepare'), $_REQUEST)) {
call_user_func(array($action_obj, 'handle'), $_REQUEST); try {
if ($action_obj->prepare($_REQUEST)) {
$action_obj->handle($_REQUEST);
}
} catch (ClientException cex) {
$cac = new ClientErrorAction();
$cac->handle(array('code' => $cex->code,
'message' => $cex->message));
} catch (ServerException sex) { // snort snort guffaw
$sac = new ServerErrorAction();
$sac->handle(array('code' => $sex->code,
'message' => $sex->message));
} catch (Exception ex) {
$sac = new ServerErrorAction();
$sac->handle(array('code' => 500,
'message' => $ex->message));
} }
} else { }
common_user_error(_('Unknown action'));
}

View File

@ -789,11 +789,12 @@ class Action extends HTMLOutputter // lawsuit
* *
* @return nothing * @return nothing
*/ */
function serverError($msg, $code=500) function serverError($msg, $code=500)
{ {
$action = $this->trimmed('action'); $action = $this->trimmed('action');
common_debug("Server error '$code' on '$action': $msg", __FILE__); common_debug("Server error '$code' on '$action': $msg", __FILE__);
common_server_error($msg, $code); throw new ServerException($msg, $code);
} }
/** /**
@ -804,11 +805,12 @@ class Action extends HTMLOutputter // lawsuit
* *
* @return nothing * @return nothing
*/ */
function clientError($msg, $code=400) function clientError($msg, $code=400)
{ {
$action = $this->trimmed('action'); $action = $this->trimmed('action');
common_debug("User error '$code' on '$action': $msg", __FILE__); common_debug("User error '$code' on '$action': $msg", __FILE__);
common_user_error($msg, $code); throw new ClientException($msg, $code);
} }
/** /**