summaryrefslogtreecommitdiffstats
path: root/lib/Controller
diff options
context:
space:
mode:
authorPaul Tirk <paultirk@paultirk.com>2021-03-24 18:56:39 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-04-08 10:23:11 +0200
commitd4ace06ff54b8e3232e7d5730f7f159292924963 (patch)
treeef7230bd80f6ad094e9ca0e2a0ba5f1884edb82a /lib/Controller
parent05b7ed79945a35f752be9152c60792d67db4be6c (diff)
add json error response without an exception
Signed-off-by: Paul Tirk <paultirk@paultirk.com>
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);
}
}