phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] api/errorhandler.inc.php, 1.1.2.2


From: nomail
Subject: [Phpgroupware-cvs] api/errorhandler.inc.php, 1.1.2.2
Date: Mon, 28 Jun 2004 16:12:57 +0200

Update of /api
Modified Files:
        Branch: proposal-branch
          errorhandler.inc.php

date: 2004/06/28 14:12:57;  author: dcech;  state: Exp;  lines: +70 -20

Log Message:
added 'numeric' type to validate
added phpgw_error support for apps to return an error code
updated xmlrpc interface for better error handling
=====================================================================
Index: api/errorhandler.inc.php
diff -u api/errorhandler.inc.php:1.1.2.1 api/errorhandler.inc.php:1.1.2.2
--- api/errorhandler.inc.php:1.1.2.1    Fri Apr 16 20:59:49 2004
+++ api/errorhandler.inc.php    Mon Jun 28 14:12:57 2004
@@ -54,6 +54,7 @@
        // display error message if appropriate
        if ($errno & error_reporting())
        {
+               /** This should be handled by the interface - dcech **/
                if (@is_object($GLOBALS['msgbox']))
                {
                        switch ($errno)
@@ -100,12 +101,12 @@
                
                // make up XML formatted error entry
                $err = '<error>'."\n"
-                        . '    <datetime>'.date("Y-m-d H:i:s 
(T)",$timestamp).'</datetime>'."\n"
-                        . '    <errornum>'.$errno.'</errornum>'."\n"
-                        . '    
<errortype>'.$errtype[$errno].'</errortype>'."\n"
-                        . '    <errormsg>'.$errmsg.'</errormsg>'."\n"
-                        . '    <scriptname>'.$filename.'</scriptname>'."\n"
-                        . '    <linenum>'.$linenum.'</linenum>'."\n"
+                        . '  
<datetime>'.gmdate('r',$timestamp).'</datetime>'."\n"
+                        . '  <errornum>'.$errno.'</errornum>'."\n"
+                        . '  <errortype>'.$errtype[$errno].'</errortype>'."\n"
+                        . '  <errormsg>'.$errmsg.'</errormsg>'."\n"
+                        . '  <scriptname>'.$filename.'</scriptname>'."\n"
+                        . '  <linenum>'.$linenum.'</linenum>'."\n"
                         . '</error>'."\n";
                
                // save to the error log
@@ -115,11 +116,11 @@
                        if (@is_object($GLOBALS['phpgw']->db))
                        {
                                $err_details = array(
-                                       'timestamp'             => 
$GLOBALS['phpgw']->db->quote ($timestamp),
-                                       'errornum'              => 
$GLOBALS['phpgw']->db->quote ($errno),
-                                       'errormsg'              => 
$GLOBALS['phpgw']->db->quote ($errmsg),
-                                       'scriptname'    => 
$GLOBALS['phpgw']->db->quote ($file),
-                                       'linenum'               => 
$GLOBALS['phpgw']->db->quote ($line)
+                                       'timestamp'             => 
$GLOBALS['phpgw']->db->quote($timestamp),
+                                       'errornum'              => 
$GLOBALS['phpgw']->db->quote($errno),
+                                       'errormsg'              => 
$GLOBALS['phpgw']->db->quote($errmsg),
+                                       'scriptname'    => 
$GLOBALS['phpgw']->db->quote($file),
+                                       'linenum'               => 
$GLOBALS['phpgw']->db->quote($line)
                                );
                                
                                // write to error table
@@ -130,12 +131,10 @@
                        }
                        
                        // if database not available or failed
-                       switch (TRUE)
+                       if (!isset($rs) || !is_object($rs))
                        {
-                               case !isset($rs):
-                               case !is_object($rs):
-                                       // write to log file
-                                       @error_log($err,3,$errconf['log_file']);
+                               // write to log file
+                               @error_log($err,3,$errconf['log_file']);
                        }
                }
                
@@ -160,18 +159,18 @@
 // report all errors and warnings, but not notices
 if (@isset($GLOBALS['phpgw_data']['errconf']['err_report']))
 {
-       error_reporting ((int)$GLOBALS['phpgw_data']['errconf']['err_report']);
+       error_reporting((int)$GLOBALS['phpgw_data']['errconf']['err_report']);
 }
 
 // use custom error handler
-set_error_handler ('phpgw_error_handler');
+set_error_handler('phpgw_error_handler');
 
 // ADOdb Error Handling
 define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
 define('ADODB_ERROR_HANDLER','adodb_error_handler');
 
 /**
-* Default Error Handler. This will be called with the following params
+* ADOdb Error Handler. This will be called with the following params
 *
 * @param $dbms         the RDBMS you are connecting to
 * @param $fn           the name of the calling function (in uppercase)
@@ -222,6 +221,57 @@
        
phpgw_error_handler(ADODB_ERROR_HANDLER_TYPE,$s,$item['file'],$item['line']);
 }
 
+class phpgw_error
+{
+       var $message;
+       var $errno;
+       
+       var $file;
+       var $line;
+       
+       function phpgw_error($message,$errno)
+       {
+               $this->message = $message;
+               $this->errno = $errno;
+               
+               $this->file = __FILE__;
+               $this->line = __LINE__;
+               
+               if (function_exists('debug_backtrace'))
+               {
+                       $backtrace = debug_backtrace();
+                       
+                       foreach ($backtrace as $trace_item)
+                       {
+                               if ($trace_item['function'] != 'phpgw_error')
+                               {
+                                       break;
+                               }
+                               
+                               $item = $trace_item;
+                       }
+                       
+                       $this->file = $item['file'];
+                       $this->line = $item['line'];
+               }
+       }
+       
+       function trigger()
+       {
+               
phpgw_error_handler($this->errno,$this->message,$this->file,$this->line);
+       }
+}
+
+function &phpgw_error($message,$errno = E_USER_WARNING)
+{
+       return new phpgw_error($message,$errno);
+}
+
+function is_error($error)
+{
+       return is_object($error) && get_class($error) == 'phpgw_error';
+}
+
 /*
  * end of script
- */
+ */
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]