mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
added catching of the exceptions
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user