diff --git a/app/config/errors.php b/app/config/errors.php index 67ddc68312..4a6f08d432 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -731,6 +731,11 @@ return [ 'description' => 'Presence with the requested ID could not be found.', 'code' => 404, ], + Exception::PRESENCE_ALREADY_EXISTS => [ + 'name' => Exception::PRESENCE_ALREADY_EXISTS, + 'description' => 'Presence with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', + 'code' => 409, + ], /** Databases */ Exception::DATABASE_NOT_FOUND => [ diff --git a/src/Appwrite/Databases/PresenceState.php b/src/Appwrite/Databases/PresenceState.php index af7185f94a..0dab0bed63 100644 --- a/src/Appwrite/Databases/PresenceState.php +++ b/src/Appwrite/Databases/PresenceState.php @@ -92,9 +92,9 @@ class PresenceState return $presence; } catch (DuplicateException $e) { - throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS, params: [$presenceId], previous: $e); + throw new Exception(Exception::PRESENCE_ALREADY_EXISTS, params: [$presenceId], previous: $e); } catch (NotFoundException $e) { - throw new Exception(Exception::DOCUMENT_NOT_FOUND, params: [$presenceId], previous: $e); + throw new Exception(Exception::PRESENCE_NOT_FOUND, params: [$presenceId], previous: $e); } catch (StructureException $e) { throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage(), previous: $e); } catch (ConflictException $e) { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 0cac0f4262..6506127c59 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -204,6 +204,7 @@ class Exception extends \Exception /** Presence */ public const string PRESENCE_NOT_FOUND = 'presence_not_found'; + public const string PRESENCE_ALREADY_EXISTS = 'presence_already_exists'; /** Databases */ public const string DATABASE_NOT_FOUND = 'database_not_found'; diff --git a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php index 68c6909f62..5e040701bb 100644 --- a/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php +++ b/src/Appwrite/Platform/Modules/Presences/HTTP/Update.php @@ -181,7 +181,7 @@ class Update extends PlatformAction try { $presence = $dbForProject->updateDocument('presenceLogs', $presenceId, $updates); } catch (Duplicate $e) { - throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS, params: [$presenceId], previous: $e); + throw new Exception(Exception::PRESENCE_ALREADY_EXISTS, params: [$presenceId], previous: $e); } catch (StructureException $e) { throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage(), previous: $e); } catch (ConflictException $e) {