summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-02-09 07:15:52 -0500
committerEvan Prodromou <evan@controlyourself.ca>2009-02-09 07:15:52 -0500
commitaa06d760b375c0cc9bbc693bf4bd412e9fda8f50 (patch)
tree8a7f82e7bd30adb2dd120eba9f4364e983d27520 /index.php
parent9152c0bdc8e23ca0ff03c72c5891d3db9c5e9d4f (diff)
Index and Action use Exceptions
Main Web entry point accepts exceptions, and main code in Action throws them.
Diffstat (limited to 'index.php')
-rw-r--r--index.php29
1 files changed, 23 insertions, 6 deletions
diff --git a/index.php b/index.php
index 387b642e2..075ee9676 100644
--- a/index.php
+++ b/index.php
@@ -47,7 +47,11 @@ if (!$user && common_config('site', 'private') &&
$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;
@@ -66,9 +70,22 @@ if (file_exists($actionfile)) {
}
$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'));
-} \ No newline at end of file
+}