public static function handleException(Exception $e)
 {
     switch (get_class($e)) {
         case 'RecordValidationException':
             return static::handleValidationError($e);
         default:
             $report = sprintf("<h1 style='color:red'>%s caught</h1>\n", get_class($e));
             $report .= sprintf("<h2>Details</h2>\n<pre>%s</pre>\n", print_r($e, true));
             $report .= sprintf("<h2>URI</h2>\n<p>%s</p>\n", htmlspecialchars($_SERVER['REQUEST_URI']));
             $report .= sprintf("<h2>_SERVER</h2>\n<pre>%s</pre>\n", print_r($_SERVER, true));
             if ($GLOBALS['Session']->Person) {
                 $report .= sprintf("<h2>User</h2>\n<pre>%s</pre>\n", print_r($GLOBALS['Session']->Person->getData(), true));
             }
             $report .= ErrorHandler::formatBacktrace(debug_backtrace());
             $report .= '<h2>Debug Log</h2><pre>' . print_r(DebugLog::getLog(), true) . '</pre>';
             if (Site::$debug) {
                 die($report);
             } else {
                 Email::send(Site::$webmasterEmail, 'Unhandeld ' . get_class($e) . ' on ' . $_SERVER['HTTP_HOST'], $report);
                 ErrorHandler::handleFailure('There was a problem... our technical staff has been notified. Please retry later.');
             }
     }
 }
Exemplo n.º 2
0
 protected static function handleError($query = '', $queryLog = false)
 {
     // save queryLog
     if ($queryLog) {
         $queryLog['error'] = static::$_mysqli->error;
         self::finishQueryLog($queryLog);
     }
     // get error message
     if ($query == 'connect') {
         $message = mysqli_connect_error();
     } elseif (static::$_mysqli->errno == 1062) {
         throw new DuplicateKeyException(static::$_mysqli->error);
     } else {
         $message = static::$_mysqli->error;
     }
     // respond
     $report = sprintf("<h1 style='color:red'>Database Error</h1>\n");
     $report .= sprintf("<h2>URI</h2>\n<p>%s</p>\n", htmlspecialchars($_SERVER['REQUEST_URI']));
     $report .= sprintf("<h2>Query</h2>\n<p>%s</p>\n", htmlspecialchars($query));
     $report .= sprintf("<h2>Reported</h2>\n<p>%s</p>\n", htmlspecialchars($message));
     $report .= ErrorHandler::formatBacktrace(debug_backtrace());
     if ($GLOBALS['Session']->Person) {
         $report .= sprintf("<h2>User</h2>\n<pre>%s</pre>\n", var_export($GLOBALS['Session']->Person->data, true));
     }
     if (self::$DebugMode) {
         print $report;
         DebugLog::dumpLog();
         exit;
     } else {
         Email::send(self::$AdministratorEmail, 'Database error on ' . $_SERVER['HTTP_HOST'], $report);
         ErrorHandler::handleFailure('Error while communicating with database', ErrorHandler::ERROR_DB);
     }
 }