diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php | 25 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php | 6 |
2 files changed, 7 insertions, 24 deletions
diff --git a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php index 4f7c2286827..dce2f9c45e4 100644 --- a/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php +++ b/apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php @@ -94,26 +94,9 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { $level = \OCP\Util::DEBUG; } - $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"; - } - - $user = \OC_User::getUser(); - - $exception = [ - 'Message' => $message, - 'Exception' => $exceptionClass, - 'Code' => $ex->getCode(), - 'Trace' => $ex->getTraceAsString(), - 'File' => $ex->getFile(), - 'Line' => $ex->getLine(), - 'User' => $user, - ]; - $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); + $this->logger->logException($ex, [ + 'app' => $this->appName, + 'level' => $level, + ]); } } diff --git a/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php index 8088ee6dc4d..85ede2ad681 100644 --- a/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php @@ -71,13 +71,13 @@ class ExceptionLoggerPluginTest extends TestCase { $this->plugin->logException($exception); $this->assertEquals($expectedLogLevel, $this->logger->level); - $this->assertStringStartsWith('Exception: {"Message":"' . $expectedMessage, $this->logger->message); + $this->assertStringStartsWith('Exception: {"Exception":' . json_encode(get_class($exception)) . ',"Message":"' . $expectedMessage . '",', $this->logger->message); } public function providesExceptions() { return [ - [0, 'HTTP\/1.1 404 Not Found', new NotFound()], - [4, 'HTTP\/1.1 400 This path leads to nowhere', new InvalidPath('This path leads to nowhere')] + [0, '', new NotFound()], + [4, 'This path leads to nowhere', new InvalidPath('This path leads to nowhere')] ]; } |