mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
update: remove duplicate exceptions from global handler.
This commit is contained in:
parent
3a88c74109
commit
6b53337a23
5 changed files with 45 additions and 17 deletions
|
|
@ -1177,13 +1177,6 @@ App::error()
|
|||
case 'Utopia\Database\Exception\Timeout':
|
||||
$error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, previous: $error);
|
||||
break;
|
||||
case 'Utopia\Database\Exception\Duplicate':
|
||||
$error = new AppwriteException(
|
||||
$isTablesAPI
|
||||
? AppwriteException::ROW_ALREADY_EXISTS
|
||||
: AppwriteException::DOCUMENT_ALREADY_EXISTS
|
||||
);
|
||||
// no break
|
||||
case 'Utopia\Database\Exception\Authorization':
|
||||
$error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,16 @@ abstract class Action extends UtopiaAction
|
|||
: Exception::TABLE_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the appropriate index invalid exception.
|
||||
*/
|
||||
final protected function getInvalidIndexException(): string
|
||||
{
|
||||
return $this->isCollectionsAPI()
|
||||
? Exception::INDEX_INVALID
|
||||
: Exception::COLUMN_INDEX_INVALID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the exception to throw when the resource is not found.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use Utopia\Database\Document;
|
|||
use Utopia\Database\Exception\Duplicate as DuplicateException;
|
||||
use Utopia\Database\Exception\Index as IndexException;
|
||||
use Utopia\Database\Exception\Limit as LimitException;
|
||||
use Utopia\Database\Exception\NotFound as NotFoundException;
|
||||
use Utopia\Database\Exception\Relationship as RelationshipException;
|
||||
use Utopia\Database\Exception\Structure as StructureException;
|
||||
use Utopia\Database\Exception\Truncate as TruncateException;
|
||||
|
|
@ -592,14 +591,14 @@ abstract class Action extends UtopiaAction
|
|||
formatOptions: $options,
|
||||
newKey: $newKey ?? null
|
||||
);
|
||||
} catch (TruncateException) {
|
||||
throw new Exception($this->getInvalidResizeException());
|
||||
} catch (NotFoundException) {
|
||||
throw new Exception($this->getNotFoundException());
|
||||
} catch (LimitException) {
|
||||
throw new Exception($this->getLimitException());
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception($this->getDuplicateException());
|
||||
} catch (IndexException $e) {
|
||||
throw new Exception($this->getInvalidIndexException(), $e->getMessage());
|
||||
} catch (LimitException) {
|
||||
throw new Exception($this->getLimitException());
|
||||
} catch (TruncateException) {
|
||||
throw new Exception($this->getInvalidResizeException());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -610,7 +609,11 @@ abstract class Action extends UtopiaAction
|
|||
->setAttribute('$id', ID::custom($db->getSequence() . '_' . $collection->getSequence() . '_' . $newKey))
|
||||
->setAttribute('key', $newKey);
|
||||
|
||||
$dbForProject->updateDocument('attributes', $originalUid, $attribute);
|
||||
try {
|
||||
$dbForProject->updateDocument('attributes', $originalUid, $attribute);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception($this->getDuplicateException());
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Document $index
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ use Appwrite\Utopia\Response as UtopiaResponse;
|
|||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Duplicate as DuplicateException;
|
||||
use Utopia\Database\Exception\Index as IndexException;
|
||||
use Utopia\Database\Exception\Limit as LimitException;
|
||||
use Utopia\Database\Exception\NotFound as NotFoundException;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
|
|
@ -86,6 +88,7 @@ class Create extends Action
|
|||
|
||||
$collectionId = $collectionId === 'unique()' ? ID::unique() : $collectionId;
|
||||
|
||||
// Map aggregate permissions into the multiple permissions they represent.
|
||||
$permissions = Permission::aggregate($permissions) ?? [];
|
||||
|
||||
try {
|
||||
|
|
@ -105,6 +108,22 @@ class Create extends Action
|
|||
throw new Exception($this->getDuplicateException());
|
||||
} catch (LimitException) {
|
||||
throw new Exception($this->getLimitException());
|
||||
} catch (NotFoundException) {
|
||||
throw new Exception(Exception::DATABASE_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$dbForProject->createCollection(
|
||||
id: 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(),
|
||||
permissions: $permissions,
|
||||
documentSecurity: $documentSecurity
|
||||
);
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception($this->getDuplicateException());
|
||||
} catch (IndexException) {
|
||||
throw new Exception($this->getInvalidIndexException());
|
||||
} catch (LimitException) {
|
||||
throw new Exception($this->getLimitException());
|
||||
}
|
||||
|
||||
$queueForEvents
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use Utopia\Database\Database;
|
|||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Duplicate as DuplicateException;
|
||||
use Utopia\Database\Exception\NotFound as NotFoundException;
|
||||
use Utopia\Database\Exception\Relationship as RelationshipException;
|
||||
use Utopia\Database\Exception\Structure as StructureException;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
|
|
@ -245,12 +246,14 @@ class Create extends Action
|
|||
|
||||
try {
|
||||
$document = $dbForProject->createDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $document);
|
||||
} catch (StructureException $e) {
|
||||
throw new Exception($this->getInvalidStructureException(), $e->getMessage());
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception($this->getDuplicateException());
|
||||
} catch (NotFoundException) {
|
||||
throw new Exception($this->getParentNotFoundException());
|
||||
} catch (RelationshipException $e) {
|
||||
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
|
||||
} catch (StructureException $e) {
|
||||
throw new Exception($this->getInvalidStructureException(), $e->getMessage());
|
||||
}
|
||||
|
||||
// Add $collectionId and $databaseId for all documents
|
||||
|
|
|
|||
Loading…
Reference in a new issue