From ecd77cb2e361ab614f958d857d1199a2cf7a5fe3 Mon Sep 17 00:00:00 2001 From: arnab Date: Wed, 16 Apr 2025 17:53:39 +0530 Subject: [PATCH] added order exception in projects and vcs --- app/controllers/api/projects.php | 15 ++++++++++----- app/controllers/api/vcs.php | 9 +++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index b29bd227aa..1762c565c7 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -28,6 +28,7 @@ use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; @@ -357,11 +358,15 @@ App::get('/v1/projects') } $filterQueries = Query::groupByType($queries)['filters']; - - $response->dynamic(new Document([ - 'projects' => $dbForPlatform->find('projects', $queries), - 'total' => $dbForPlatform->count('projects', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_PROJECT_LIST); + try { + $response->dynamic(new Document([ + 'projects' => $dbForPlatform->find('projects', $queries), + 'total' => $dbForPlatform->count('projects', $filterQueries, APP_LIMIT_COUNT), + ]), Response::MODEL_PROJECT_LIST); + } catch (OrderException $e) { + $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + } }); App::get('/v1/projects/:projectId') diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 2c145febcc..a230ae5d0c 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -19,6 +19,7 @@ use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; @@ -1113,8 +1114,12 @@ App::get('/v1/vcs/installations') } $filterQueries = Query::groupByType($queries)['filters']; - - $results = $dbForPlatform->find('installations', $queries); + try { + $results = $dbForPlatform->find('installations', $queries); + } catch (OrderException $e) { + $message = "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."; + throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, $message); + } $total = $dbForPlatform->count('installations', $filterQueries, APP_LIMIT_COUNT); $response->dynamic(new Document([