public static function errorHandler($method, $args, $exception, $logError = true)
{
if ($logError) {
Logger::error($exception);
Logger::error(["message" => $exception->getMessage(), "method" => $method, "arguments" => $args]);
}
$lowerErrorMessage = strtolower($exception->getMessage());
// check if the mysql-connection is the problem (timeout issues, ...)
if (strpos($lowerErrorMessage, "mysql server has gone away") !== false || strpos($lowerErrorMessage, "lost connection") !== false) {
// wait a few seconds
sleep(5);
// the connection to the server has probably been lost, try to reconnect and call the method again
try {
Logger::warning("The connection to the MySQL-Server has probably been lost, try to reconnect...");
self::reset();
Logger::warning("Reconnecting to the MySQL-Server was successful, sending the command again to the server.");
$r = self::get()->callResourceMethod($method, $args);
Logger::warning("Resending the command was successful");
return $r;
} catch (\Exception $e) {
Logger::error($e);
throw $e;
}
}
// no handling throw it again
throw $exception;
}