(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) <noreply@anthropic.com>
This commit is contained in:
Jake Barnby
2026-04-18 00:47:33 +12:00
co-authored by Claude Opus 4.7
parent e8006dce6e
commit 1225aa4861
@@ -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';