mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
update: collections <> tables errors.
This commit is contained in:
+10
-10
@@ -657,20 +657,20 @@ return [
|
||||
'code' => 400,
|
||||
],
|
||||
|
||||
/** Collections */
|
||||
Exception::COLLECTION_NOT_FOUND => [
|
||||
'name' => Exception::COLLECTION_NOT_FOUND,
|
||||
'description' => 'Collection with the requested ID could not be found.',
|
||||
/** Tables */
|
||||
Exception::TABLE_NOT_FOUND => [
|
||||
'name' => Exception::TABLE_NOT_FOUND,
|
||||
'description' => 'Table with the requested ID could not be found.',
|
||||
'code' => 404,
|
||||
],
|
||||
Exception::COLLECTION_ALREADY_EXISTS => [
|
||||
'name' => Exception::COLLECTION_ALREADY_EXISTS,
|
||||
'description' => 'A collection with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.',
|
||||
Exception::TABLE_ALREADY_EXISTS => [
|
||||
'name' => Exception::TABLE_ALREADY_EXISTS,
|
||||
'description' => 'A table with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.',
|
||||
'code' => 409,
|
||||
],
|
||||
Exception::COLLECTION_LIMIT_EXCEEDED => [
|
||||
'name' => Exception::COLLECTION_LIMIT_EXCEEDED,
|
||||
'description' => 'The maximum number of collections has been reached.',
|
||||
Exception::TABLE_LIMIT_EXCEEDED => [
|
||||
'name' => Exception::TABLE_LIMIT_EXCEEDED,
|
||||
'description' => 'The maximum number of tables has been reached.',
|
||||
'code' => 400,
|
||||
],
|
||||
|
||||
|
||||
@@ -1185,7 +1185,7 @@ App::error()
|
||||
$error = new AppwriteException(AppwriteException::RELATIONSHIP_VALUE_INVALID, $error->getMessage(), previous: $error);
|
||||
break;
|
||||
case 'Utopia\Database\Exception\NotFound':
|
||||
$error = new AppwriteException(AppwriteException::COLLECTION_NOT_FOUND, $error->getMessage(), previous: $error);
|
||||
$error = new AppwriteException(AppwriteException::TABLE_NOT_FOUND, $error->getMessage(), previous: $error);
|
||||
break;
|
||||
case 'Utopia\Database\Exception\Dependency':
|
||||
$error = new AppwriteException(AppwriteException::INDEX_DEPENDENCY, null, previous: $error);
|
||||
|
||||
@@ -192,9 +192,9 @@ class Exception extends \Exception
|
||||
public const DATABASE_QUERY_ORDER_NULL = 'database_query_order_null';
|
||||
|
||||
/** Collections */
|
||||
public const COLLECTION_NOT_FOUND = 'collection_not_found';
|
||||
public const COLLECTION_ALREADY_EXISTS = 'collection_already_exists';
|
||||
public const COLLECTION_LIMIT_EXCEEDED = 'collection_limit_exceeded';
|
||||
public const TABLE_NOT_FOUND = 'table_not_found';
|
||||
public const TABLE_ALREADY_EXISTS = 'table_already_exists';
|
||||
public const TABLE_LIMIT_EXCEEDED = 'table_limit_exceeded';
|
||||
|
||||
/** Documents */
|
||||
public const DOCUMENT_NOT_FOUND = 'document_not_found';
|
||||
|
||||
@@ -78,7 +78,7 @@ class Action extends UtopiaAction
|
||||
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (!empty($format)) {
|
||||
@@ -100,7 +100,7 @@ class Action extends UtopiaAction
|
||||
$options['side'] = Database::RELATION_SIDE_PARENT;
|
||||
$relatedTable = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection'] ?? '');
|
||||
if ($relatedTable->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND, 'The related table was not found.');
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND, 'The related table was not found.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ class Action extends UtopiaAction
|
||||
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
|
||||
|
||||
@@ -81,7 +81,7 @@ class Delete extends Action
|
||||
|
||||
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
|
||||
@@ -109,7 +109,7 @@ class Delete extends Action
|
||||
if ($options['twoWay']) {
|
||||
$relatedTable = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection']);
|
||||
if ($relatedTable->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$relatedColumn = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $relatedTable->getInternalId() . '_' . $options['twoWayKey']);
|
||||
|
||||
@@ -75,7 +75,7 @@ class Get extends Action
|
||||
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$column = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
|
||||
|
||||
@@ -105,13 +105,13 @@ class Create extends ColumnAction
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
$table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId());
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$relatedTableDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedTableId);
|
||||
$relatedTable = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $relatedTableDocument->getInternalId());
|
||||
if ($relatedTable->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$columns = $table->getAttribute('attributes', []);
|
||||
|
||||
@@ -68,7 +68,7 @@ class XList extends Action
|
||||
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$queries = Query::parseQueries($queries);
|
||||
|
||||
@@ -85,7 +85,7 @@ class Create extends Action
|
||||
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$count = $dbForProject->count('indexes', [
|
||||
|
||||
@@ -74,7 +74,7 @@ class Delete extends Action
|
||||
$table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$index = $dbForProject->getDocument('indexes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key);
|
||||
|
||||
@@ -67,7 +67,7 @@ class Get extends Action
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$index = $table->find('key', $key, 'indexes');
|
||||
|
||||
@@ -73,7 +73,7 @@ class XList extends Action
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$queries = Query::parseQueries($queries);
|
||||
|
||||
@@ -106,7 +106,7 @@ class Create extends Action
|
||||
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
|
||||
|
||||
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$allowedPermissions = [
|
||||
@@ -246,7 +246,7 @@ class Create extends Action
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS);
|
||||
} catch (NotFoundException) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class Delete extends Action
|
||||
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
|
||||
|
||||
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Read permission should not be required for delete
|
||||
@@ -102,7 +102,7 @@ class Delete extends Action
|
||||
);
|
||||
});
|
||||
} catch (NotFoundException) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Add $tableId and $databaseId for all rows
|
||||
|
||||
@@ -79,7 +79,7 @@ class Get extends Action
|
||||
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
|
||||
|
||||
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -81,7 +81,7 @@ class XList extends Action
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$row = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), $rowId);
|
||||
|
||||
@@ -101,7 +101,7 @@ class Update extends Action
|
||||
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
|
||||
|
||||
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Read permission should not be required for update
|
||||
@@ -243,7 +243,7 @@ class Update extends Action
|
||||
} catch (StructureException $e) {
|
||||
throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage());
|
||||
} catch (NotFoundException) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Add $tableId and $databaseId for all rows
|
||||
|
||||
@@ -79,7 +79,7 @@ class XList extends Action
|
||||
$table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId));
|
||||
|
||||
if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -99,9 +99,9 @@ class Create extends Action
|
||||
|
||||
$dbForProject->createCollection('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), permissions: $permissions, documentSecurity: $documentSecurity);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::COLLECTION_ALREADY_EXISTS);
|
||||
throw new Exception(Exception::TABLE_ALREADY_EXISTS);
|
||||
} catch (LimitException) {
|
||||
throw new Exception(Exception::COLLECTION_LIMIT_EXCEEDED);
|
||||
throw new Exception(Exception::TABLE_LIMIT_EXCEEDED);
|
||||
}
|
||||
|
||||
$queueForEvents
|
||||
|
||||
@@ -71,7 +71,7 @@ class Delete extends Action
|
||||
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (!$dbForProject->deleteDocument('database_' . $database->getInternalId(), $tableId)) {
|
||||
|
||||
@@ -66,7 +66,7 @@ class Get extends Action
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$response->dynamic($table, UtopiaResponse::MODEL_TABLE);
|
||||
|
||||
@@ -81,7 +81,7 @@ class XList extends Action
|
||||
$table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $tableDocument->getInternalId());
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -77,7 +77,7 @@ class Update extends Action
|
||||
|
||||
$table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId);
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$permissions ??= $table->getPermissions() ?? [];
|
||||
|
||||
@@ -68,7 +68,7 @@ class Get extends Action
|
||||
$table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $tableDocument->getInternalId());
|
||||
|
||||
if ($table->isEmpty()) {
|
||||
throw new Exception(Exception::COLLECTION_NOT_FOUND);
|
||||
throw new Exception(Exception::TABLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$periods = Config::getParam('usage', []);
|
||||
|
||||
@@ -3491,7 +3491,7 @@ class DatabasesCustomServerTest extends Scope
|
||||
]), $payload);
|
||||
|
||||
$this->assertEquals(404, $update['headers']['status-code']);
|
||||
$this->assertEquals(AppwriteException::COLLECTION_NOT_FOUND, $update['body']['type']);
|
||||
$this->assertEquals(AppwriteException::TABLE_NOT_FOUND, $update['body']['type']);
|
||||
|
||||
/**
|
||||
* Check if Attribute exists
|
||||
|
||||
Reference in New Issue
Block a user