diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index f13c9703c5..388a015cb5 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -24,6 +24,7 @@ use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\NotFound as NotFoundException; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; @@ -216,11 +217,15 @@ App::get('/v1/storage/buckets') } $filterQueries = Query::groupByType($queries)['filters']; - - $response->dynamic(new Document([ - 'buckets' => $dbForProject->find('buckets', $queries), - 'total' => $dbForProject->count('buckets', $filterQueries, APP_LIMIT_COUNT), - ]), Response::MODEL_BUCKET_LIST); + try { + $response->dynamic(new Document([ + 'buckets' => $dbForProject->find('buckets', $queries), + 'total' => $dbForProject->count('buckets', $filterQueries, APP_LIMIT_COUNT), + ]), Response::MODEL_BUCKET_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/storage/buckets/:bucketId') @@ -837,6 +842,9 @@ App::get('/v1/storage/buckets/:bucketId/files') } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); + } 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); } $response->dynamic(new Document([