diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php index e3baaf9c3d..32a497ed64 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Delete.php @@ -11,6 +11,8 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; use Utopia\Database\Database; +use Utopia\Database\Exception\Conflict as ConflictException; +use Utopia\Database\Exception\Restricted as RestrictedException; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; @@ -64,7 +66,13 @@ class Delete extends Base throw new Exception(Exception::DOCUMENT_NOT_FOUND); } - $dbForProject->deleteDocument('presenceLogs', $presenceId); + try { + $dbForProject->deleteDocument('presenceLogs', $presenceId); + } catch (ConflictException) { + throw new Exception(Exception::DOCUMENT_DELETE_RESTRICTED); + } catch (RestrictedException) { + throw new Exception(Exception::DOCUMENT_UPDATE_CONFLICT); + } $queueForEvents ->setParam('presenceId', $presence->getId()) diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Get.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Get.php index 240a2f7bf4..75323d500e 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Get.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Get.php @@ -52,7 +52,6 @@ class Get extends Base public function action(string $presenceId, Response $response, Database $dbForProject): void { $presence = $dbForProject->getDocument('presenceLogs', $presenceId); - if ($presence->isEmpty()) { throw new Exception(Exception::DOCUMENT_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php index 3298108b04..e932a2b42a 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php @@ -12,6 +12,9 @@ use Appwrite\Utopia\Database\Documents\User; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Conflict as ConflictException; +use Utopia\Database\Exception\Duplicate; +use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Permissions; @@ -97,6 +100,9 @@ class Update extends PresenceAction if ($userId !== null) { $updateData['userId'] = $userId; $userDoc = $dbForProject->getDocument('users', $userId); + if ($userDoc->isEmpty()) { + throw new Exception(Exception::USER_NOT_FOUND, params: [$userId]); + } $updateData['userInternalId'] = $userDoc->getSequence(); } @@ -123,7 +129,15 @@ class Update extends PresenceAction return; } - $presence = $dbForProject->updateDocument('presenceLogs', $presenceId, $updates); + try { + $presence = $dbForProject->updateDocument('presenceLogs', $presenceId, $updates); + } catch (Duplicate $e) { + throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS, params: [$presenceId], previous: $e); + } catch (StructureException $e) { + throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage(), previous: $e); + } catch (ConflictException $e) { + throw new Exception(Exception::DOCUMENT_UPDATE_CONFLICT, $e->getMessage(), previous: $e); + } $queueForEvents->setParam('presenceId', $presence->getId()); $response->dynamic($presence, Response::MODEL_PRESENCE); diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/XList.php b/src/Appwrite/Platform/Modules/Presences/HTTP/XList.php index 64b8a80d31..fb8203c7e2 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/XList.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/XList.php @@ -13,6 +13,8 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; +use Utopia\Database\Exception\Relationship as RelationshipException; +use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Platform\Action; @@ -94,6 +96,10 @@ class XList extends Base $total = $includeTotal ? $dbForProject->count('presenceLogs', $filterQueries, APP_LIMIT_COUNT) : 0; } catch (OrderException $e) { throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); + } catch (StructureException $e) { + throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage(), previous: $e); + } catch (RelationshipException $e) { + throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage(), previous: $e); } $response->dynamic(new Document([