From b7f4f575219a5b9ccd2d09da89e07fe6a61a87c6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 7 Jun 2023 13:51:24 +1200 Subject: [PATCH 1/2] Add new error message to differentiate between missing data and missing data + permissions for document updates --- app/config/errors.php | 7 ++++++- app/controllers/api/databases.php | 2 +- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 9fadde6e93..450ea08141 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -403,9 +403,14 @@ return [ 'description' => 'The document structure is invalid. Please ensure the attributes match the collection definition.', 'code' => 400, ], + Exception::DOCUMENT_MISSING_DATA => [ + 'name' => Exception::DOCUMENT_MISSING_DATA, + 'description' => 'The document data is missing.', + 'code' => 400, + ], Exception::DOCUMENT_MISSING_PAYLOAD => [ 'name' => Exception::DOCUMENT_MISSING_PAYLOAD, - 'description' => 'The document payload is missing.', + 'description' => 'The document data or permissions must be provided.', 'code' => 400, ], Exception::DOCUMENT_ALREADY_EXISTS => [ diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c4ff448ce4..a4de380561 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2653,7 +2653,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array if (empty($data)) { - throw new Exception(Exception::DOCUMENT_MISSING_PAYLOAD); + throw new Exception(Exception::DOCUMENT_MISSING_DATA); } if (isset($data['$id'])) { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index ebd12851e2..7ed022b452 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -134,6 +134,7 @@ class Exception extends \Exception /** Documents */ public const DOCUMENT_NOT_FOUND = 'document_not_found'; public const DOCUMENT_INVALID_STRUCTURE = 'document_invalid_structure'; + public const DOCUMENT_MISSING_DATA = 'document_missing_data'; public const DOCUMENT_MISSING_PAYLOAD = 'document_missing_payload'; public const DOCUMENT_ALREADY_EXISTS = 'document_already_exists'; public const DOCUMENT_UPDATE_CONFLICT = 'document_update_conflict'; From ed2c1139a788608516ab08827addaadd95bd57ff Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 9 Jun 2023 13:03:19 +1200 Subject: [PATCH 2/2] Update messages --- app/config/errors.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 450ea08141..2983d22cd8 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -405,12 +405,12 @@ return [ ], Exception::DOCUMENT_MISSING_DATA => [ 'name' => Exception::DOCUMENT_MISSING_DATA, - 'description' => 'The document data is missing.', + 'description' => 'The document data is missing. You must provide the document data.', 'code' => 400, ], Exception::DOCUMENT_MISSING_PAYLOAD => [ 'name' => Exception::DOCUMENT_MISSING_PAYLOAD, - 'description' => 'The document data or permissions must be provided.', + 'description' => 'The document data and permissions are missing. You must provide either the document data or permissions to be updated.', 'code' => 400, ], Exception::DOCUMENT_ALREADY_EXISTS => [