Better exception handling in index

Some better exception handling in Web entry point.
This commit is contained in:
Evan Prodromou 2009-02-09 07:25:35 -05:00
parent aa06d760b3
commit 5466f6a6d0
2 changed files with 16 additions and 15 deletions

View File

@ -48,9 +48,8 @@ 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 = new ClientErrorAction(_('Unknown action'), 404);
$cac->handle(array('code' => 404, $cac->showPage();
'message' => _('Unknown action')));
} else { } else {
include_once $actionfile; include_once $actionfile;
@ -75,17 +74,14 @@ if (!file_exists($actionfile)) {
if ($action_obj->prepare($_REQUEST)) { if ($action_obj->prepare($_REQUEST)) {
$action_obj->handle($_REQUEST); $action_obj->handle($_REQUEST);
} }
} catch (ClientException cex) { } catch (ClientException $cex) {
$cac = new ClientErrorAction(); $cac = new ClientErrorAction($cex->getMessage(), $cex->getCode());
$cac->handle(array('code' => $cex->code, $cac->showPage();
'message' => $cex->message)); } catch (ServerException $sex) { // snort snort guffaw
} catch (ServerException sex) { // snort snort guffaw $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode());
$sac = new ServerErrorAction(); $sac->showPage();
$sac->handle(array('code' => $sex->code, } catch (Exception $ex) {
'message' => $sex->message)); $sac = new ServerErrorAction($ex->getMessage());
} catch (Exception ex) { $sac->showPage();
$sac = new ServerErrorAction();
$sac->handle(array('code' => 500,
'message' => $ex->message));
} }
} }

View File

@ -182,6 +182,8 @@ foreach ($_config_files as $_config_file) {
} }
} }
// XXX: how many of these could be auto-loaded on use?
require_once('Validate.php'); require_once('Validate.php');
require_once('markdown.php'); require_once('markdown.php');
@ -193,6 +195,9 @@ require_once(INSTALLDIR.'/lib/subs.php');
require_once(INSTALLDIR.'/lib/Shorturl_api.php'); require_once(INSTALLDIR.'/lib/Shorturl_api.php');
require_once(INSTALLDIR.'/lib/twitter.php'); require_once(INSTALLDIR.'/lib/twitter.php');
require_once(INSTALLDIR.'/lib/clientexception.php');
require_once(INSTALLDIR.'/lib/serverexception.php');
// XXX: other formats here // XXX: other formats here
define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER); define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);