Hi, we are moving onto production, and need to make sure we are not showing any weird error to our end users, specially fatal errors, already tried adding the following to my MODx.class but the error is still shown, what I’m missing?
/**
* Loads the error handler for this instance.
*
* @param array|null $options An array of options for the errorHandler.
*/
protected function _initErrorHandler($options = null) {
if ($this->errorHandler == null || !is_object($this->errorHandler)) {
if ($ehClass = $this->getOption('error_handler_class', $options, 'modErrorHandler', true)) {
$ehPath = $this->getOption('error_handler_path', $options, '', true);
if ($ehClass = $this->loadClass($ehClass, $ehPath, false, true)) {
if ($this->errorHandler = new $ehClass($this)) {
// $result = set_error_handler(array ($this->errorHandler, 'handleError'), $this->getOption('error_handler_types', $options, error_reporting(), true));
$result = set_error_handler('myErrorHandler');
if ($result === false) {
$this->log(modX::LOG_LEVEL_ERROR, 'Could not set error handler. Make sure your class has a function called handleError(). Result: ' . print_r($result, true));
}
set_exception_handler('exception_handler');
register_shutdown_function("fatal_handler");
$this->log(modX::LOG_LEVEL_ERROR, 'Exc handler set1! ');
}
}
}
}
}
/**
* Simple error handling method
**/
function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
$this->log(modX::LOG_LEVEL_ERROR, 'Non managed exepction found! ');
return true;
}
function fatal_handler() {
$errfile = "unknown file";
$errstr = "shutdown";
$errno = E_CORE_ERROR;
$errline = 0;
$error = error_get_last();
$this->log(modX::LOG_LEVEL_ERROR, 'Fatal!!!');
if($error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
echo "Uncaught exception: " , $errstr, "\n";
}
$this->log(modX::LOG_LEVEL_ERROR, 'Non managed exepction found! ');
return true;
}
function myErrorHandler($errno, $errstr, $errfile, $errline) {
echo "<b>Custom error:</b> [$errno] $errstr<br>";
echo " Error on line $errline in $errfile<br>";
$this->log(modX::LOG_LEVEL_ERROR, 'Non managed exepction found! ');
return true;
}