Improve logging of exceptions catched by SharingMiddleware

This commit is contained in:
Julius Haertl
2017-02-27 11:27:49 +01:00
parent 67f26ef9b2
commit 15e5a432b6
3 changed files with 39 additions and 27 deletions

View File

@@ -23,18 +23,32 @@
namespace OCA\Deck\Middleware;
use OCA\Deck\StatusException;
use \OCP\AppFramework\Middleware;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\JSONResponse;
use OCP\ILogger;
use OCP\Util;
use OCP\IConfig;
class SharingMiddleware extends Middleware {
/** @var ILogger */
private $logger;
/** @var IConfig */
private $config;
/**
* SharingMiddleware constructor.
*
* @param ILogger $logger
* @param IConfig $config
*/
public function __construct(ILogger $logger, IConfig $config) {
$this->logger = $logger;
$this->config = $config;
}
/**
* Return JSON error response if the user has no sufficient permission
*
@@ -46,6 +60,9 @@ class SharingMiddleware extends Middleware {
*/
public function afterException($controller, $methodName, \Exception $exception) {
if ($exception instanceof StatusException) {
if($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
$this->logger->logException($exception);
}
return new JSONResponse([
"status" => $exception->getStatus(),
"message" => $exception->getMessage()