Avoid logging normal exceptions in remote.php
When the instance needs an upgrade, or a file is not found, no logging will occur to avoid filling up log files
This commit is contained in:
parent
03965053c3
commit
b4532028f9
11
remote.php
11
remote.php
|
@ -33,6 +33,7 @@ use Sabre\DAV\Server;
|
||||||
/**
|
/**
|
||||||
* Class RemoteException
|
* Class RemoteException
|
||||||
* Dummy exception class to be use locally to identify certain conditions
|
* Dummy exception class to be use locally to identify certain conditions
|
||||||
|
* Will not be logged to avoid DoS
|
||||||
*/
|
*/
|
||||||
class RemoteException extends Exception {
|
class RemoteException extends Exception {
|
||||||
}
|
}
|
||||||
|
@ -47,7 +48,10 @@ function handleException(Exception $e) {
|
||||||
if ($isXmlContentType === 0) {
|
if ($isXmlContentType === 0) {
|
||||||
// fire up a simple server to properly process the exception
|
// fire up a simple server to properly process the exception
|
||||||
$server = new Server();
|
$server = new Server();
|
||||||
$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
|
if (!($e instanceof RemoteException)) {
|
||||||
|
// we shall not log on RemoteException
|
||||||
|
$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
|
||||||
|
}
|
||||||
$server->on('beforeMethod', function () use ($e) {
|
$server->on('beforeMethod', function () use ($e) {
|
||||||
if ($e instanceof RemoteException) {
|
if ($e instanceof RemoteException) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
|
@ -67,11 +71,12 @@ function handleException(Exception $e) {
|
||||||
if ($e instanceof \OC\ServiceUnavailableException ) {
|
if ($e instanceof \OC\ServiceUnavailableException ) {
|
||||||
$statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE;
|
$statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
\OCP\Util::writeLog('remote', $e->getMessage(), \OCP\Util::FATAL);
|
|
||||||
if ($e instanceof RemoteException) {
|
if ($e instanceof RemoteException) {
|
||||||
|
// we shall not log on RemoteException
|
||||||
OC_Response::setStatus($e->getCode());
|
OC_Response::setStatus($e->getCode());
|
||||||
OC_Template::printErrorPage($e->getMessage());
|
OC_Template::printErrorPage($e->getMessage());
|
||||||
} else {
|
} else {
|
||||||
|
\OCP\Util::writeLog('remote', $e->getMessage(), \OCP\Util::FATAL);
|
||||||
OC_Response::setStatus($statusCode);
|
OC_Response::setStatus($statusCode);
|
||||||
OC_Template::printExceptionErrorPage($e);
|
OC_Template::printExceptionErrorPage($e);
|
||||||
}
|
}
|
||||||
|
@ -122,7 +127,7 @@ try {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!\OC::$server->getAppManager()->isInstalled($app)) {
|
if (!\OC::$server->getAppManager()->isInstalled($app)) {
|
||||||
throw new Exception('App not installed: ' . $app);
|
throw new RemoteException('App not installed: ' . $app);
|
||||||
}
|
}
|
||||||
OC_App::loadApp($app);
|
OC_App::loadApp($app);
|
||||||
$file = OC_App::getAppPath($app) .'/'. $parts[1];
|
$file = OC_App::getAppPath($app) .'/'. $parts[1];
|
||||||
|
|
Loading…
Reference in New Issue