From 1284df2cb48714c4a3f8426191b2e65f89ace4cd Mon Sep 17 00:00:00 2001 From: fogelito Date: Mon, 26 Feb 2024 14:12:40 +0200 Subject: [PATCH] Duplicate message --- app/controllers/api/databases.php | 8 ++++-- composer.json | 2 +- composer.lock | 27 ++++++++++++------- phpunit.xml | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 2 ++ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 6a9cb73a67..7cc826170d 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -3495,8 +3495,12 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum ); } catch (AuthorizationException) { throw new Exception(Exception::USER_UNAUTHORIZED); - } catch (DuplicateException) { - throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS); + } catch (DuplicateException $exception) { + $message = 'Document with the requested ID already exists. '; + $message .= !is_null($exception->getCollectionId()) ? ' In Collection ' . $exception->getCollectionId() : ''; + $message .= !is_null($exception->getDocumentId()) ? ' Id ' . $exception->getDocumentId() : ''; + $message .= 'Try again with a different ID or use ID.unique() to generate a unique ID.'; + throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS, $message); } catch (StructureException $exception) { throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $exception->getMessage()); } diff --git a/composer.json b/composer.json index 40d8df92e4..50bd4dfda6 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "utopia-php/cache": "0.9.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.48.*", + "utopia-php/database": "dev-duplicate_exceptions_info as 0.48.4", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.*", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 9eb8dd1fa7..55b989cbf5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ed4d8b871471fe6a259742c4abe88184", + "content-hash": "59dbd35558ca65064a13a846f7760312", "packages": [ { "name": "adhocore/jwt", @@ -1552,16 +1552,16 @@ }, { "name": "utopia-php/database", - "version": "0.48.4", + "version": "dev-duplicate_exceptions_info", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "02f20bd901b8fab26d7dc2c58f7da1d6a08d21c0" + "reference": "c257bc7b5ea72b3e0a48816acb475a6a3698852b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/02f20bd901b8fab26d7dc2c58f7da1d6a08d21c0", - "reference": "02f20bd901b8fab26d7dc2c58f7da1d6a08d21c0", + "url": "https://api.github.com/repos/utopia-php/database/zipball/c257bc7b5ea72b3e0a48816acb475a6a3698852b", + "reference": "c257bc7b5ea72b3e0a48816acb475a6a3698852b", "shasum": "" }, "require": { @@ -1602,9 +1602,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.48.4" + "source": "https://github.com/utopia-php/database/tree/duplicate_exceptions_info" }, - "time": "2024-02-23T03:22:55+00:00" + "time": "2024-02-26T11:50:21+00:00" }, { "name": "utopia-php/domains", @@ -5447,9 +5447,18 @@ "time": "2023-10-10T11:58:32+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-duplicate_exceptions_info", + "alias": "0.48.4", + "alias_normalized": "0.48.4.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/phpunit.xml b/phpunit.xml index 90ebd4225f..e772866051 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index d91122e4fa..a06934dfa7 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -3575,6 +3575,8 @@ trait DatabasesBase ]); $this->assertEquals(409, $duplicate['headers']['status-code']); + var_dump($duplicate); + $this->assertEquals('---', '___---'); return $data; }