From b5cc7e4aabeddd08a27e02b2249ce86f92f96fac Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 11 Feb 2009 14:45:06 -0500 Subject: Handle DB_DataObject errors better We try to handle DB_DataObject errors a little bit better. Previously, they just spit out a cryptic string to the browser with a suggestion to turn on debugging (not a good idea!). So, we catch the error, write the full error message to the log, and then tell users that the can contact the admins if they need to. --- index.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 717b17361..4db0e7555 100644 --- a/index.php +++ b/index.php @@ -25,7 +25,8 @@ require_once INSTALLDIR . '/lib/common.php'; $user = null; $action = null; -function getPath($req) { +function getPath($req) +{ if (common_config('site', 'fancy')) { return $req['p']; } else if ($_SERVER['PATH_INFO']) { @@ -35,10 +36,30 @@ function getPath($req) { } } -function main() { +function handleError($error) +{ + common_log(LOG_ERR, "PEAR error: " . $error->getMessage()); + $msg = sprintf(_('The database for %s isn\'t responding correctly, '. + 'so the site won\'t work properly. '. + 'The site admins probably know about the problem, '. + 'but you can contact them at %s to make sure. '. + 'Otherwise, wait a few minutes and try again.'), + common_config('site', 'name'), + common_config('site', 'email')); + + $dac = new DBErrorAction($msg, 500); + $dac->showPage(); + exit(-1); +} +function main() +{ global $user, $action; + // For database errors + + PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError'); + // XXX: we need a little more structure in this script // get and cache current user -- cgit v1.2.3-54-g00ecf