update: remove conflict, restrict and relationship exceptions from global handler.

This commit is contained in:
Darshan 2025-06-11 13:42:55 +05:30
parent 3f81847267
commit e07a1817ab
5 changed files with 51 additions and 30 deletions

View file

@ -1174,14 +1174,6 @@ App::error()
break;
}
break;
case 'Utopia\Database\Exception\Conflict':
$error = new AppwriteException(
$isTablesAPI
? AppwriteException::ROW_UPDATE_CONFLICT
: AppwriteException::DOCUMENT_UPDATE_CONFLICT,
previous: $error
);
break;
case 'Utopia\Database\Exception\Timeout':
$error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, previous: $error);
break;
@ -1203,20 +1195,9 @@ App::error()
? AppwriteException::ROW_ALREADY_EXISTS
: AppwriteException::DOCUMENT_ALREADY_EXISTS
);
break;
case 'Utopia\Database\Exception\Restricted':
$error = new AppwriteException(
$isTablesAPI
? AppwriteException::ROW_DELETE_RESTRICTED
: AppwriteException::DOCUMENT_DELETE_RESTRICTED
);
break;
case 'Utopia\Database\Exception\Authorization':
$error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED);
break;
case 'Utopia\Database\Exception\Relationship':
$error = new AppwriteException(AppwriteException::RELATIONSHIP_VALUE_INVALID, $error->getMessage(), previous: $error);
break;
case 'Utopia\Database\Exception\NotFound':
$error = new AppwriteException(
$isTablesAPI

View file

@ -14,6 +14,8 @@ 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;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Validator\Authorization;
@ -124,6 +126,16 @@ abstract class Action extends UtopiaAction
: Exception::COLUMN_ALREADY_EXISTS;
}
/**
* Get the correct invalid structure message.
*/
final protected function getInvalidStructureException(): string
{
return $this->isCollectionsAPI()
? Exception::DOCUMENT_INVALID_STRUCTURE
: Exception::ROW_INVALID_STRUCTURE;
}
/**
* Get the appropriate limit exceeded exception.
*/
@ -541,8 +553,14 @@ abstract class Action extends UtopiaAction
newKey: $newKey,
onDelete: $primaryDocumentOptions['onDelete'],
);
} catch (NotFoundException) {
throw new Exception($this->getNotFoundException());
} catch (IndexException) {
throw new Exception(Exception::INDEX_INVALID);
} catch (LimitException) {
throw new Exception($this->getLimitException());
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {
throw new Exception($this->getInvalidStructureException(), $e->getMessage());
}
if ($primaryDocumentOptions['twoWay']) {

View file

@ -97,6 +97,25 @@ abstract class Action extends UtopiaAction
: Exception::ROW_ALREADY_EXISTS;
}
/**
* Get the appropriate conflict exception.
*/
final protected function getConflictException(): string
{
return $this->isCollectionsAPI()
? Exception::DOCUMENT_UPDATE_CONFLICT
: Exception::ROW_UPDATE_CONFLICT;
}
/**
* Get the appropriate delete restricted exception.
*/
final protected function getRestrictedException(): string
{
return $this->isCollectionsAPI()
? Exception::DOCUMENT_DELETE_RESTRICTED
: Exception::ROW_DELETE_RESTRICTED;
}
/**
* Get the correct invalid structure message.

View file

@ -13,7 +13,8 @@ use Appwrite\SDK\Response as SDKResponse;
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\Conflict as ConflictException;
use Utopia\Database\Exception\Restricted as RestrictedException;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\UID;
use Utopia\Platform\Scope\HTTP;
@ -108,8 +109,10 @@ class Delete extends Action
$documentId
);
});
} catch (NotFoundException) {
throw new Exception($this->getParentNotFoundException());
} catch (ConflictException) {
throw new Exception($this->getConflictException());
} catch (RestrictedException) {
throw new Exception($this->getRestrictedException());
}
// Add $collection and $databaseId for all documents

View file

@ -13,9 +13,9 @@ use Appwrite\SDK\Response as SDKResponse;
use Appwrite\Utopia\Response as UtopiaResponse;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\Authorization as AuthorizationException;
use Utopia\Database\Exception\Conflict as ConflictException;
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;
@ -239,14 +239,14 @@ class Update extends Action
$newDocument
)
);
} catch (AuthorizationException) {
throw new Exception(Exception::USER_UNAUTHORIZED);
} catch (ConflictException) {
throw new Exception($this->getConflictException());
} catch (DuplicateException) {
throw new Exception($this->getDuplicateException());
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {
throw new Exception($this->getInvalidStructureException(), $e->getMessage());
} catch (NotFoundException) {
throw new Exception($this->getParentNotFoundException());
}
// Add $collectionId and $databaseId for all documents