diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-03-11 11:53:31 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-03-11 11:53:31 +0100 |
commit | 0f3e36fdfd1c57f5212c495d59b0e5964df8a4ac (patch) | |
tree | 83e5af893f29ffa91459a77417edce15c4f99c46 /lib | |
parent | cfaee93552b519b8e017e63fd5a82b1e5c9f951b (diff) | |
download | nextcloud-server-0f3e36fdfd1c57f5212c495d59b0e5964df8a4ac.tar.gz nextcloud-server-0f3e36fdfd1c57f5212c495d59b0e5964df8a4ac.zip |
Adding a more meaningful message for sabre dav exception - fixes #14516
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/connector/sabre/exceptionloggerplugin.php | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/private/connector/sabre/exceptionloggerplugin.php b/lib/private/connector/sabre/exceptionloggerplugin.php index 2bd43e56f55..a0dc6e7c182 100644 --- a/lib/private/connector/sabre/exceptionloggerplugin.php +++ b/lib/private/connector/sabre/exceptionloggerplugin.php @@ -10,6 +10,10 @@ namespace OC\Connector\Sabre; +use OCP\ILogger; +use Sabre\DAV\Exception; +use Sabre\HTTP\Response; + class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { private $nonFatalExceptions = array( 'Sabre\DAV\Exception\NotAuthenticated' => true, @@ -22,13 +26,19 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { 'Sabre\DAV\Exception\PreconditionFailed' => true, ); + /** @var string */ private $appName; + /** @var ILogger */ + private $logger; + /** * @param string $loggerAppName app name to use when logging + * @param ILogger $logger */ - public function __construct($loggerAppName = 'webdav') { + public function __construct($loggerAppName, $logger) { $this->appName = $loggerAppName; + $this->logger = $logger; } /** @@ -50,14 +60,30 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { /** * Log exception * - * @internal param Exception $e exception */ - public function logException($e) { - $exceptionClass = get_class($e); + public function logException(\Exception $ex) { + $exceptionClass = get_class($ex); $level = \OCP\Util::FATAL; if (isset($this->nonFatalExceptions[$exceptionClass])) { $level = \OCP\Util::DEBUG; } - \OCP\Util::logException($this->appName, $e, $level); + + $message = $ex->getMessage(); + if ($ex instanceof Exception) { + if (empty($message)) { + $response = new Response($ex->getHTTPCode()); + $message = $response->getStatusText(); + } + $message = "HTTP/1.1 {$ex->getHTTPCode()} $message"; + } + + $exception = [ + 'Message' => $message, + 'Code' => $ex->getCode(), + 'Trace' => $ex->getTraceAsString(), + 'File' => $ex->getFile(), + 'Line' => $ex->getLine(), + ]; + $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); } } |