From 1225aa4861cbe1ba65dc167b79c33cf6cebe93d7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 18 Apr 2026 00:47:33 +1200 Subject: [PATCH] (fix): translate NotFound from find() into 404 on listDocuments When a DocumentsDB collection's metadata document exists but the backing store (e.g. a freshly restored dedicated shard) has no table, Utopia\Database\Database::find() throws NotFound. Previously this bubbled to the HTTP layer as a generic 500. Catch it in the same try/catch that already handles OrderException, QueryException, and Timeout, and translate into COLLECTION_NOT_FOUND/TABLE_NOT_FOUND via getParentNotFoundException() so the caller sees the correct 404. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Http/Databases/Collections/Documents/XList.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index aeee280615..96af0491e7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -14,6 +14,7 @@ use Appwrite\Utopia\Database\Documents\User; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\NotFound as NotFoundException; use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Exception\Timeout; @@ -195,6 +196,11 @@ class XList extends Action $documents = $find(); $total = $includeTotal ? $dbForDatabases->count($collectionTableId, $queries, APP_LIMIT_COUNT) : 0; } + } catch (NotFoundException) { + // The collection metadata document exists but the backing store (e.g. a + // dedicated DocumentsDB shard) has no table for it. Treat this as a + // not-found on the collection so the caller sees a 404 instead of a 500. + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } catch (OrderException $e) { $documents = $this->isCollectionsAPI() ? 'documents' : 'rows'; $attribute = $this->isCollectionsAPI() ? 'attribute' : 'column';