error handling code improved

This commit is contained in:
Steffen Schröder 2014-05-07 21:37:37 +02:00
parent 5b04257c9a
commit 50697bfb4f

View File

@ -127,13 +127,12 @@ class ErrorHandler {
* @param string $errorString * @param string $errorString
* @param string $errorFile * @param string $errorFile
* @param int $errorLine * @param int $errorLine
* @param array $errorContext
* @return bool * @return bool
*/ */
public function handleError($errorNumber, $errorString, $errorFile = null, $errorLine = -1) { public function handleError($errorNumber, $errorString, $errorFile = null, $errorLine = -1, array $errorContext = array()) {
$userError = $this->isUserErrorNumber($errorNumber); if (error_reporting() === 0) {
return false;
if (!$userError && error_reporting() === 0) {
return;
} }
$errorTag = $this->getErrorTag($errorNumber); $errorTag = $this->getErrorTag($errorNumber);
@ -145,7 +144,7 @@ class ErrorHandler {
$logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine . PHP_EOL . 'Trace: ' . $traceString; $logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine . PHP_EOL . 'Trace: ' . $traceString;
logMessage($logMessage); logMessage($logMessage);
if ($this->reportErrors && !$userError) { if ($this->reportErrors && !$this->isUserErrorNumber($errorNumber)) {
$error = array(); $error = array();
$error['Type'] = 'Error'; $error['Type'] = 'Error';
$error['Message'] = $message; $error['Message'] = $message;
@ -156,15 +155,12 @@ class ErrorHandler {
if ($this->maniaControl->server) { if ($this->maniaControl->server) {
$error['ServerLogin'] = $this->maniaControl->server->login; $error['ServerLogin'] = $this->maniaControl->server->login;
} else {
$error['ServerLogin'] = '';
} }
if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) { if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL); $error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
$error['ManiaControlVersion'] = ManiaControl::VERSION . '#' . $this->maniaControl->updateManager->getNightlyBuildDate(); $error['ManiaControlVersion'] = ManiaControl::VERSION . ' ' . $this->maniaControl->updateManager->getNightlyBuildDate();
} else { } else {
$error['UpdateChannel'] = '';
$error['ManiaControlVersion'] = ManiaControl::VERSION; $error['ManiaControlVersion'] = ManiaControl::VERSION;
} }
@ -173,15 +169,15 @@ class ErrorHandler {
$url = ManiaControl::URL_WEBSERVICE . 'errorreport?error=' . urlencode($info); $url = ManiaControl::URL_WEBSERVICE . 'errorreport?error=' . urlencode($info);
$success = FileUtil::loadFile($url); $success = FileUtil::loadFile($url);
$success = json_decode($success);
if (!json_decode($success)) { if ($success) {
logMessage('Error-Report failed!');
} else {
logMessage('Error successfully reported!'); logMessage('Error successfully reported!');
} else {
logMessage('Error-Report failed!');
} }
} }
if ($this->shouldStopExecution($errorNumber)) { if ($this->shouldStopExecution($errorNumber)) {
logMessage('Stopping execution...'); logMessage('Stopping Execution...');
exit(); exit();
} }
return false; return false;