diff options
Diffstat (limited to 'lib/private/AppFramework/Middleware/OCSMiddleware.php')
-rw-r--r-- | lib/private/AppFramework/Middleware/OCSMiddleware.php | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php index 5016fc3eec8..64f4b0054de 100644 --- a/lib/private/AppFramework/Middleware/OCSMiddleware.php +++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php @@ -1,35 +1,15 @@ <?php + /** - * - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OC\AppFramework\Middleware; use OC\AppFramework\Http; use OC\AppFramework\OCS\BaseResponse; use OC\AppFramework\OCS\V1Response; use OC\AppFramework\OCS\V2Response; -use OCP\API; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; @@ -40,7 +20,6 @@ use OCP\AppFramework\OCSController; use OCP\IRequest; class OCSMiddleware extends Middleware { - /** @var IRequest */ private $request; @@ -80,7 +59,7 @@ class OCSMiddleware extends Middleware { if ($controller instanceof OCSController && $exception instanceof OCSException) { $code = $exception->getCode(); if ($code === 0) { - $code = API::RESPOND_UNKNOWN_ERROR; + $code = \OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR; } return $this->buildNewResponse($controller, $code, $exception->getMessage()); @@ -101,15 +80,23 @@ class OCSMiddleware extends Middleware { * we need to catch the response and convert it to a proper OCS response. */ if ($controller instanceof OCSController && !($response instanceof BaseResponse)) { - if ($response->getStatus() === Http::STATUS_UNAUTHORIZED || - $response->getStatus() === Http::STATUS_FORBIDDEN) { + if ($response->getStatus() === Http::STATUS_UNAUTHORIZED) { + $message = ''; + if ($response instanceof JSONResponse) { + /** @var DataResponse $response */ + $message = $response->getData()['message']; + } + + return $this->buildNewResponse($controller, OCSController::RESPOND_UNAUTHORISED, $message); + } + if ($response->getStatus() === Http::STATUS_FORBIDDEN) { $message = ''; if ($response instanceof JSONResponse) { /** @var DataResponse $response */ $message = $response->getData()['message']; } - return $this->buildNewResponse($controller, API::RESPOND_UNAUTHORISED, $message); + return $this->buildNewResponse($controller, Http::STATUS_FORBIDDEN, $message); } } |