Ok, understand!... you must do :
in your index.php
set_exception_handler(function($e) {
$error = new \Common\Helpers\CoreHelper();
return $error->handleException($e);
});
set_error_handler(function($errorCode, $errorMessage, $errorFile, $errorLine, $errcontext) {
$error = new \Common\Helpers\CoreHelper();
return $error->handleError($errorCode, $errorMessage, $errorFile, $errorLine, $errcontext);
});
on your controller:
public function handleException($e) {
if (ob_get_level() > 0) {
ob_end_clean();
}
$this->_fnformatHandlerException($e);
header("Location: /common/error/index.html/600");
}
public function handleError($errorCode, $errorMessage, $errorFile, $errorLine, $application = null) {
if (ob_get_level() > 0) {
ob_end_clean();
}
$this->_fnformatHandlerError($errorCode, $errorMessage, $errorFile, $errorLine, $application = null);
header("Location: /common/error/index.html/601");
}
public function _fnformatHandlerException($e) {
$request = new \Phalcon\Http\Request();
$errors = array(
'info' => get_class($e) . '[' . $e->getCode() . ']: ',
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'extraInfo' => $request->getClientAddress(),
'trace' => "\n" . $e->getTraceAsString() . "\n"
);
$string = str_replace(" ", "", str_replace("'", "", substr($e->getMessage(), 0, 100)));
$uniqueError = $e->getCode() . $e->getLine() . $string;
$json_errors = json_encode($errors);
$this->_fnlogger($json_errors, $uniqueError);
}
public function _fnformatHandlerError($errorCode, $errorMessage, $errorFile, $errorLine, $errcontext = null) {
$request = new \Phalcon\Http\Request();
$errors = array(
'info' => $errorCode,
'message' => $errorMessage,
'file' => $errorFile,
'line' => $errorLine,
'extraInfo' => $request->getClientAddress(),
'trace' => "\n" . $errcontext . "\n"
);
$string = str_replace(" ", "", str_replace("'", "", substr($errorMessage, 0, 100)));
$uniqueError = $errorCode . $errorLine . $string;
$json_errors = json_encode($errors);
$this->_fnlogger($json_errors, $uniqueError);
}
public function _fnlogger($json_errors, $uniqueError) {
$logger = DI::getDefault()->getLogger();
$logger->error($json_errors, array($uniqueError));
$logger->close();
}
public function handleException($e) {
if (ob_get_level() > 0) {
ob_end_clean();
}
$this->_fnformatHandlerException($e);
header("Location: /common/error/index.html/600");
}
public function handleError($errorCode, $errorMessage, $errorFile, $errorLine, $application = null) {
if (ob_get_level() > 0) {
ob_end_clean();
}
$this->_fnformatHandlerError($errorCode, $errorMessage, $errorFile, $errorLine, $application = null);
header("Location: /common/error/index.html/601");
}
public function _fnformatHandlerException($e) {
$request = new \Phalcon\Http\Request();
$errors = array(
'info' => get_class($e) . '[' . $e->getCode() . ']: ',
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'extraInfo' => $request->getClientAddress(),
'trace' => "\n" . $e->getTraceAsString() . "\n"
);
$string = str_replace(" ", "", str_replace("'", "", substr($e->getMessage(), 0, 100)));
$uniqueError = $e->getCode() . $e->getLine() . $string;
$json_errors = json_encode($errors);
$this->_fnlogger($json_errors, $uniqueError);
}
public function _fnformatHandlerError($errorCode, $errorMessage, $errorFile, $errorLine, $errcontext = null) {
$request = new \Phalcon\Http\Request();
$errors = array(
'info' => $errorCode,
'message' => $errorMessage,
'file' => $errorFile,
'line' => $errorLine,
'extraInfo' => $request->getClientAddress(),
'trace' => "\n" . $errcontext . "\n"
);
$string = str_replace(" ", "", str_replace("'", "", substr($errorMessage, 0, 100)));
$uniqueError = $errorCode . $errorLine . $string;
$json_errors = json_encode($errors);
$this->_fnlogger($json_errors, $uniqueError);
}
public function _fnlogger($json_errors, $uniqueError) {
$logger = DI::getDefault()->getLogger();
$logger->error($json_errors, array($uniqueError));
$logger->close();
}
this is my own hander error and exception :)