]> source.dussan.org Git - nextcloud-server.git/commitdiff
only execute code if exception was thrown by the corresponding controller
authorBjoern Schiessle <bjoern@schiessle.org>
Mon, 13 Mar 2017 11:13:57 +0000 (12:13 +0100)
committerBjoern Schiessle <bjoern@schiessle.org>
Fri, 24 Mar 2017 10:06:44 +0000 (11:06 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/federation/lib/Middleware/AddServerMiddleware.php
apps/federation/tests/Middleware/AddServerMiddlewareTest.php

index d920aee3e4ecf3e1323cb1b6b51b6e886161974f..71e517f6b87dd8b941b230218b72205de634f237 100644 (file)
@@ -25,6 +25,7 @@
 namespace OCA\Federation\Middleware;
 
 use OC\HintException;
+use OCA\Federation\Controller\SettingsController;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\JSONResponse;
 use OCP\AppFramework\Middleware;
@@ -57,6 +58,9 @@ class AddServerMiddleware extends Middleware {
         * @return JSONResponse
         */
        public function afterException($controller, $methodName, \Exception $exception) {
+               if (($controller instanceof SettingsController) === false) {
+                       throw $exception;
+               }
                $this->logger->error($exception->getMessage(), ['app' => $this->appName]);
                if ($exception instanceof HintException) {
                        $message = $exception->getHint();
index b2096cb3730441c0f7cf97793780acdf1c51515a..6c502c66f5f12ef89a6d0b6906544bf43638fb27 100644 (file)
@@ -26,8 +26,8 @@ namespace OCA\Federation\Tests\Middleware;
 
 
 use OC\HintException;
+use OCA\Federation\Controller\SettingsController;
 use OCA\Federation\Middleware\AddServerMiddleware;
-use OCP\AppFramework\Controller;
 use OCP\AppFramework\Http;
 use OCP\IL10N;
 use OCP\ILogger;
@@ -44,7 +44,7 @@ class AddServerMiddlewareTest extends TestCase {
        /** @var  AddServerMiddleware */
        private $middleware;
 
-       /** @var  \PHPUnit_Framework_MockObject_MockObject | Controller */
+       /** @var  \PHPUnit_Framework_MockObject_MockObject | SettingsController */
        private $controller;
 
        public function setUp() {
@@ -52,7 +52,7 @@ class AddServerMiddlewareTest extends TestCase {
 
                $this->logger = $this->getMockBuilder(ILogger::class)->getMock();
                $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
-               $this->controller = $this->getMockBuilder(Controller::class)
+               $this->controller = $this->getMockBuilder(SettingsController::class)
                        ->disableOriginalConstructor()->getMock();
 
                $this->middleware = new AddServerMiddleware(