示例#1
0
 /**
  * return the generic error message (errorMessage in the configuration).
  * Replaced the %code% pattern in the message by the current error code
  * @return string
  */
 public function getGenericErrorMessage()
 {
     $msg = $GLOBALS['gJConfig']->error_handling['errorMessage'];
     if ($this->errorMessage) {
         $code = $this->errorMessage->getCode();
     } else {
         $code = '';
     }
     return str_replace('%code%', $code, $msg);
 }
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     if ($this->request) {
         // we have config, so we can process "normally"
         $errorLog->setFormat($gJConfig->error_handling['messageLogFormat']);
         jLog::log($errorLog, $type);
         $this->allErrorMessages[] = $errorLog;
         // if non fatal error, it is finished
         if ($type != 'error') {
             return;
         }
         $this->errorMessage = $errorLog;
         while (ob_get_level()) {
             ob_end_clean();
         }
         if ($this->response) {
             $resp = $this->response;
         } else {
             $resp = $this->response = new jResponseCmdline();
         }
         $resp->outputErrors();
         jSession::end();
     } elseif ($type != 'error') {
         $this->allErrorMessages[] = $errorLog;
         $this->initErrorMessages[] = $errorLog;
         return;
     } else {
         // fatal error appeared during init, let's display a single message
         while (ob_get_level()) {
             ob_end_clean();
         }
         // log into file
         @error_log($errorLog->getFormatedMessage(), 3, jApp::logPath('errors.log'));
         // output text response
         echo 'Error during initialization: ' . $message . ' (' . $file . ' ' . $line . ")\n";
     }
     exit(1);
 }
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     $errorLog->setFormat(jApp::config()->error_handling['messageLogFormat']);
     jLog::log($errorLog, $type);
     $this->allErrorMessages[] = $errorLog;
     if ($type != 'error') {
         return;
     }
     $this->errorMessage = $errorLog;
     while (ob_get_level() && @ob_end_clean()) {
     }
     if ($this->response) {
         $resp = $this->response;
     } else {
         require_once JELIX_LIB_CORE_PATH . 'response/jResponseCmdline.class.php';
         $resp = $this->response = new jResponseCmdline();
     }
     $resp->outputErrors();
     jSession::end();
     exit(1);
 }
 static function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     // for non fatal error appeared during init, let's just store it for loggers later
     if ($type != 'error') {
         self::$initErrorMessages[] = $errorLog;
         return;
     } else {
         if (jServer::isCLI()) {
             // fatal error appeared during init, in a CLI context
             while (ob_get_level() && @ob_end_clean()) {
             }
             // log into file and output message in the console
             echo 'Error during initialization: \\n';
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
                 echo '* ' . $err->getMessage() . ' (' . $err->getFile() . ' ' . $err->getLine() . ")\n";
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             echo '* ' . $message . ' (' . $file . ' ' . $line . ")\n";
         } else {
             // fatal error appeared during init, let's display an HTML page
             // since we don't know the request, we cannot return a response
             // corresponding to the expected protocol
             while (ob_get_level() && @ob_end_clean()) {
             }
             // log into file
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             $msg = $errorLog->getMessage();
             if (strpos($msg, '--') !== false) {
                 list($msg, $bin) = explode('--', $msg, 2);
                 // remove confidential data
             }
             // if accept text/html
             if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
                 if (file_exists(jApp::appPath('responses/error.en_US.php'))) {
                     $file = jApp::appPath('responses/error.en_US.php');
                 } else {
                     $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
                 }
                 $HEADTOP = '';
                 $HEADBOTTOM = '';
                 $BODYTOP = '';
                 $BODYBOTTOM = htmlspecialchars($msg);
                 $BASEPATH = jApp::urlBasePath();
                 if ($BASEPATH == '') {
                     $BASEPATH = '/';
                 }
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/html');
                 include $file;
             } else {
                 // output text response
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/plain');
                 echo 'Error during initialization. ' . $msg;
             }
         }
     }
     exit(1);
 }
示例#5
0
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     $errorLog->setFormat(jApp::config()->error_handling['messageLogFormat']);
     jLog::log($errorLog, $type);
     if ($type != 'error') {
         return;
     }
     $this->errorMessage = $errorLog;
     while (ob_get_level() && @ob_end_clean()) {
     }
     $resp = $this->request->getErrorResponse($this->response);
     $resp->outputErrors();
     jSession::end();
     exit(1);
 }