summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/FolderApiV2Controller.php4
-rw-r--r--lib/Controller/JSONHttpErrorTrait.php23
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/Controller/FolderApiV2Controller.php b/lib/Controller/FolderApiV2Controller.php
index 6f2eb13da..a1fdcd44c 100644
--- a/lib/Controller/FolderApiV2Controller.php
+++ b/lib/Controller/FolderApiV2Controller.php
@@ -78,7 +78,7 @@ class FolderApiV2Controller extends ApiController
try {
$response = $this->folderService->rename($this->getUserId(), $folderId, $name);
} catch (ServiceNotFoundException $ex) {
- return $this->errorResponseV2($ex, Http::STATUS_NOT_FOUND);
+ return $this->errorResponseWithExceptionV2($ex, Http::STATUS_NOT_FOUND);
}
return $this->responseV2([
@@ -105,7 +105,7 @@ class FolderApiV2Controller extends ApiController
'folder' => $responseData
]);
} catch (ServiceNotFoundException $ex) {
- return $this->errorResponseV2($ex, Http::STATUS_NOT_FOUND);
+ return $this->errorResponseWithExceptionV2($ex, Http::STATUS_NOT_FOUND);
}
}
}
diff --git a/lib/Controller/JSONHttpErrorTrait.php b/lib/Controller/JSONHttpErrorTrait.php
index 5c5d7a8cf..3defc47c1 100644
--- a/lib/Controller/JSONHttpErrorTrait.php
+++ b/lib/Controller/JSONHttpErrorTrait.php
@@ -30,13 +30,28 @@ trait JSONHttpErrorTrait
* @param int $code
* @return \OCP\AppFramework\Http\JSONResponse
*/
- public function errorResponseV2(\Exception $exception, $code)
+ public function errorResponseWithExceptionV2(\Exception $exception, $code)
+ {
+ return $this->errorResponseV2(
+ $exception->getMessage(),
+ $exception->getCode(),
+ $code
+ );
+ }
+
+ /**
+ * @param string $message
+ * @param int $code
+ * @param int $httpStatusCode
+ * @return \OCP\AppFramework\Http\JSONResponse
+ */
+ public function errorResponseV2(string $message, int $code, int $httpStatusCode)
{
return new JSONResponse([
'error' => [
- 'code' => $exception->getCode(),
- 'message' => $exception->getMessage()
+ 'code' => $code,
+ 'message' => $message,
]
- ], $code);
+ ], $httpStatusCode);
}
}