Improve error handling when requesting nonexisting collection

This commit is contained in:
2024-09-27 16:55:23 +02:00
parent 147c15afe2
commit 588dba2730

View File

@@ -75,7 +75,11 @@ class Daemon
switch ($collectionOp) {
case null:
if ($request->getMethod() == 'GET') {
$result = $this->opCollectionGet($collectionName);
try {
$result = $this->opCollectionGet($collectionName);
} catch (\Exception $e) {
return Response::json([ 'error' => "No such collection" ])->withStatus(404);
}
return Response::json($result);
} elseif ($request->getMethod() == 'POST') {
$this->opCollectionSet($request, $collectionName);
@@ -84,7 +88,11 @@ class Daemon
throw new \Exception("Invalid request method");
case 'all':
$result = $this->opCollectionGetAll($collectionName);
try {
$result = $this->opCollectionGetAll($collectionName);
} catch (\Exception $e) {
return Response::json([ 'error' => "No such collection" ])->withStatus(404);
}
return Response::json($result);
}