]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Better exception handling in index
authorEvan Prodromou <evan@controlyourself.ca>
Mon, 9 Feb 2009 12:25:35 +0000 (07:25 -0500)
committerEvan Prodromou <evan@controlyourself.ca>
Mon, 9 Feb 2009 12:25:35 +0000 (07:25 -0500)
Some better exception handling in Web entry point.

index.php
lib/common.php

index 075ee967687a1c37d63dc60ac0d9417324973661..dac5a8071a17be2227e0e9b49b3205df25bcaa6c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -48,9 +48,8 @@ if (!$user && common_config('site', 'private') &&
 $actionfile = INSTALLDIR."/actions/$action.php";
 
 if (!file_exists($actionfile)) {
-    $cac = new ClientErrorAction();
-    $cac->handle(array('code' => 404,
-                       'message' => _('Unknown action')));
+    $cac = new ClientErrorAction(_('Unknown action'), 404);
+    $cac->showPage();
 } else {
 
     include_once $actionfile;
@@ -75,17 +74,14 @@ if (!file_exists($actionfile)) {
         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));
+    } catch (ClientException $cex) {
+        $cac = new ClientErrorAction($cex->getMessage(), $cex->getCode());
+        $cac->showPage();
+    } catch (ServerException $sex) { // snort snort guffaw
+        $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode());
+        $sac->showPage();
+    } catch (Exception $ex) {
+        $sac = new ServerErrorAction($ex->getMessage());
+        $sac->showPage();
     }
 }
index 7d3ec108ca32efc2d54c81ac2369c023feb0c460..64c7f2410a8f72f0dacfd0b1e8483db015187437 100644 (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('markdown.php');
 
@@ -193,6 +195,9 @@ require_once(INSTALLDIR.'/lib/subs.php');
 require_once(INSTALLDIR.'/lib/Shorturl_api.php');
 require_once(INSTALLDIR.'/lib/twitter.php');
 
+require_once(INSTALLDIR.'/lib/clientexception.php');
+require_once(INSTALLDIR.'/lib/serverexception.php');
+
 // XXX: other formats here
 
 define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);