/**
 * logs and then displays error messages
 *
 * @return void
 */
function handleError($error)
{
    if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
        return;
    }
    $logmsg = "PEAR error: " . $error->getMessage();
    if (common_config('site', 'logdebug')) {
        $logmsg .= " : " . $error->getDebugInfo();
    }
    // DB queries often end up with a lot of newlines; merge to a single line
    // for easier grepability...
    $logmsg = str_replace("\n", " ", $logmsg);
    common_log(LOG_ERR, $logmsg);
    // @fixme backtrace output should be consistent with exception handling
    if (common_config('site', 'logdebug')) {
        $bt = $error->getBacktrace();
        foreach ($bt as $n => $line) {
            common_log(LOG_ERR, formatBacktraceLine($n, $line));
        }
    }
    if ($error instanceof DB_DataObject_Error || $error instanceof DB_Error) {
        $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'));
    } else {
        $msg = _('An important error occured, probably related to email setup. ' . 'Check logfiles for more info..');
    }
    $dac = new DBErrorAction($msg, 500);
    $dac->showPage();
    exit(-1);
}
Example #2
0
/**
 * logs and then displays error messages
 *
 * @return void
 */
function handleError($error)
{
    if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
        return;
    }
    $logmsg = "PEAR error: " . $error->getMessage();
    if (common_config('site', 'logdebug')) {
        $logmsg .= " : " . $error->getDebugInfo();
    }
    // DB queries often end up with a lot of newlines; merge to a single line
    // for easier grepability...
    $logmsg = str_replace("\n", " ", $logmsg);
    common_log(LOG_ERR, $logmsg);
    // @fixme backtrace output should be consistent with exception handling
    if (common_config('site', 'logdebug')) {
        $bt = $error->getBacktrace();
        foreach ($bt as $n => $line) {
            common_log(LOG_ERR, formatBacktraceLine($n, $line));
        }
    }
    if ($error instanceof DB_DataObject_Error || $error instanceof DB_Error) {
        $msg = sprintf(_('数据库维护中,请稍后再访问'), common_config('site', 'name'), common_config('site', 'email'));
    } else {
        $msg = _('网站维护中,请稍后再访问');
    }
    $dac = new DBErrorAction($msg, 500);
    $dac->showPage();
    exit(-1);
}
Example #3
0
/**
 * logs and then displays error messages
 *
 * @return void
 */
function handleError($error)
{
    try {
        if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
            return;
        }
        $logmsg = "PEAR error: " . $error->getMessage();
        if ($error instanceof PEAR_Exception && common_config('site', 'logdebug')) {
            $logmsg .= " : " . $error->toText();
        }
        // DB queries often end up with a lot of newlines; merge to a single line
        // for easier grepability...
        $logmsg = str_replace("\n", " ", $logmsg);
        common_log(LOG_ERR, $logmsg);
        // @fixme backtrace output should be consistent with exception handling
        if (common_config('site', 'logdebug')) {
            $bt = $error->getTrace();
            foreach ($bt as $n => $line) {
                common_log(LOG_ERR, formatBacktraceLine($n, $line));
            }
        }
        if ($error instanceof DB_DataObject_Error || $error instanceof DB_Error || $error instanceof PEAR_Exception && $error->getCode() == -24) {
            //If we run into a DB error, assume we can't connect to the DB at all
            //so set the current user to null, so we don't try to access the DB
            //while rendering the error page.
            global $_cur;
            $_cur = null;
            $msg = sprintf(_('The database for %1$s is not responding correctly, ' . 'so the site will not work properly. ' . 'The site admins probably know about the problem, ' . 'but you can contact them at %2$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();
        } else {
            $sac = new ServerErrorAction($error->getMessage(), 500, $error);
            $sac->showPage();
        }
    } catch (Exception $e) {
        // TRANS: Error message.
        echo _('An error occurred.');
    }
    exit(-1);
}