]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - index.php
Index and Action use Exceptions
[quix0rs-gnu-social.git] / index.php
index 387b642e2c6a2e8a81772bbbf8b29f36b1c1ffcc..075ee967687a1c37d63dc60ac0d9417324973661 100644 (file)
--- 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
+}