From eaf31fdb785ea4bb3fddc25e37d96f28d31ef109 Mon Sep 17 00:00:00 2001 From: Bhaskar Singh Date: Sun, 5 Mar 2023 14:35:47 +0530 Subject: [PATCH 1/6] Updated the error to 501 error code for custom domain when _APP_DOMAIN and _APP_DOMAIN_TARGET is setup incorrectly --- app/config/errors.php | 5 +++++ app/controllers/api/projects.php | 2 +- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index 266e017e93..741fb406b8 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -474,6 +474,11 @@ return [ 'description' => 'Project with the requested ID could not be found. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.', 'code' => 404, ], + Exception::ENV_VARIABLE_INCORRECT_SETUP => [ + 'name' => Exception::ENV_VARIABLE_INCORRECT_SETUP, + 'description' => 'For Custom Domain ENV Variable is not setup correctly', + 'code' => 501, + ], Exception::PROJECT_UNKNOWN => [ 'name' => Exception::PROJECT_UNKNOWN, 'description' => 'The project ID is either missing or not valid. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.', diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 29a193748d..6dc543d2c0 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1340,7 +1340,7 @@ App::post('/v1/projects/:projectId/domains') $target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', '')); if (!$target->isKnown() || $target->isTest()) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Unreachable CNAME target (' . $target->get() . '), please use a domain with a public suffix.'); + throw new Exception(Exception::ENV_VARIABLE_INCORRECT_SETUP, 'Unreachable CNAME target (' . $target->get() . '), please use a domain with a public suffix.'); } $domain = new Domain($domain); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 8b240aa971..35ebc04b0c 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -177,6 +177,7 @@ class Exception extends \Exception public const DOMAIN_NOT_FOUND = 'domain_not_found'; public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists'; public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed'; + public const ENV_VARIABLE_INCORRECT_SETUP = 'env_variable_setup_incorrectly'; /** GraphqQL */ public const GRAPHQL_NO_QUERY = 'graphql_no_query'; From 7f3000439a39de4ba9184f0502d9ac6892a8ac72 Mon Sep 17 00:00:00 2001 From: Bhaskar Singh Date: Sun, 5 Mar 2023 14:35:47 +0530 Subject: [PATCH 2/6] Updated ENV_VARIABLE_INCORRECT_SETUP to DOMAIN_VARIABLE_INCORRECT --- app/config/errors.php | 5 +++++ app/controllers/api/projects.php | 2 +- src/Appwrite/Extend/Exception.php | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 741fb406b8..0e965d9d7e 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -539,6 +539,11 @@ return [ 'description' => 'A Domain with the requested ID already exists.', 'code' => 409, ], + Exception::DOMAIN_VERIFICATION_FAILED => [ + 'name' => Exception::DOMAIN_VARIABLE_INCORRECT, + 'description' => 'Your Appwrite instance is not publicly accessible. Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.', + 'code' => 501, + ], Exception::VARIABLE_NOT_FOUND => [ 'name' => Exception::VARIABLE_NOT_FOUND, 'description' => 'Variable with the requested ID could not be found.', diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6dc543d2c0..d9c556b462 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1340,7 +1340,7 @@ App::post('/v1/projects/:projectId/domains') $target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', '')); if (!$target->isKnown() || $target->isTest()) { - throw new Exception(Exception::ENV_VARIABLE_INCORRECT_SETUP, 'Unreachable CNAME target (' . $target->get() . '), please use a domain with a public suffix.'); + throw new Exception(Exception::DOMAIN_VERIFICATION_FAILED, 'Unreachable CNAME target (' . $target->get() . '), please use a domain with a public suffix. Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.'); } $domain = new Domain($domain); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 35ebc04b0c..fda96b4bcd 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -177,7 +177,7 @@ class Exception extends \Exception public const DOMAIN_NOT_FOUND = 'domain_not_found'; public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists'; public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed'; - public const ENV_VARIABLE_INCORRECT_SETUP = 'env_variable_setup_incorrectly'; + public const DOMAIN_VARIABLE_INCORRECT = 'domain_variable_incorrect'; /** GraphqQL */ public const GRAPHQL_NO_QUERY = 'graphql_no_query'; From 7a4cea9f79efc0a7ef555b9d26f6a471a5426689 Mon Sep 17 00:00:00 2001 From: Bhaskar Singh Date: Wed, 8 Mar 2023 17:21:37 +0530 Subject: [PATCH 3/6] Removed ENV_VARIABLE_INCORRECT_SETUP --- app/config/errors.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 0e965d9d7e..8adb8634d5 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -473,12 +473,6 @@ return [ 'name' => Exception::PROJECT_NOT_FOUND, 'description' => 'Project with the requested ID could not be found. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.', 'code' => 404, - ], - Exception::ENV_VARIABLE_INCORRECT_SETUP => [ - 'name' => Exception::ENV_VARIABLE_INCORRECT_SETUP, - 'description' => 'For Custom Domain ENV Variable is not setup correctly', - 'code' => 501, - ], Exception::PROJECT_UNKNOWN => [ 'name' => Exception::PROJECT_UNKNOWN, 'description' => 'The project ID is either missing or not valid. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.', From b16c789282d94524c0f9cdbd63fc73f399d981dd Mon Sep 17 00:00:00 2001 From: Bhaskar Singh Date: Wed, 8 Mar 2023 17:23:15 +0530 Subject: [PATCH 4/6] Fixing the bracket --- app/config/errors.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/config/errors.php b/app/config/errors.php index 8adb8634d5..a682882d2e 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -473,6 +473,7 @@ return [ 'name' => Exception::PROJECT_NOT_FOUND, 'description' => 'Project with the requested ID could not be found. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.', 'code' => 404, + ], Exception::PROJECT_UNKNOWN => [ 'name' => Exception::PROJECT_UNKNOWN, 'description' => 'The project ID is either missing or not valid. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.', From 31a903d1440c50189247f7e29fc2f7d2030b1e4b Mon Sep 17 00:00:00 2001 From: Bhaskar Singh Date: Fri, 10 Mar 2023 00:24:33 +0530 Subject: [PATCH 5/6] Updated the error message for target check fails in custom domain creation --- app/config/errors.php | 10 +++++----- app/controllers/api/projects.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index a682882d2e..ef131896fd 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -534,11 +534,6 @@ return [ 'description' => 'A Domain with the requested ID already exists.', 'code' => 409, ], - Exception::DOMAIN_VERIFICATION_FAILED => [ - 'name' => Exception::DOMAIN_VARIABLE_INCORRECT, - 'description' => 'Your Appwrite instance is not publicly accessible. Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.', - 'code' => 501, - ], Exception::VARIABLE_NOT_FOUND => [ 'name' => Exception::VARIABLE_NOT_FOUND, 'description' => 'Variable with the requested ID could not be found.', @@ -554,6 +549,11 @@ return [ 'description' => 'Domain verification for the requested domain has failed.', 'code' => 401, ], + Exception::DOMAIN_VARIABLE_INCORRECT => [ + 'name' => Exception::DOMAIN_VARIABLE_INCORRECT, + 'description' => 'Your Appwrite instance is not publicly accessible. Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.', + 'code' => 501, + ], Exception::GRAPHQL_NO_QUERY => [ 'name' => Exception::GRAPHQL_NO_QUERY, 'description' => 'Param "query" is not optional.', diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index d9c556b462..bc57cf04ac 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1340,7 +1340,7 @@ App::post('/v1/projects/:projectId/domains') $target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', '')); if (!$target->isKnown() || $target->isTest()) { - throw new Exception(Exception::DOMAIN_VERIFICATION_FAILED, 'Unreachable CNAME target (' . $target->get() . '), please use a domain with a public suffix. Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.'); + throw new Exception(Exception::DOMAIN_VARIABLE_INCORRECT, 'Unreachable CNAME target (' . $target->get() . '). Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.'); } $domain = new Domain($domain); From 8b5e0e1f1a903e7b9205f727bb269867acc41347 Mon Sep 17 00:00:00 2001 From: Bhaskar Singh Date: Tue, 21 Mar 2023 20:33:42 +0530 Subject: [PATCH 6/6] Updating the exception variable name for easy readability --- app/config/errors.php | 4 ++-- app/controllers/api/projects.php | 2 +- src/Appwrite/Extend/Exception.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index ef131896fd..0c1524772d 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -549,8 +549,8 @@ return [ 'description' => 'Domain verification for the requested domain has failed.', 'code' => 401, ], - Exception::DOMAIN_VARIABLE_INCORRECT => [ - 'name' => Exception::DOMAIN_VARIABLE_INCORRECT, + Exception::DOMAIN_TARGET_INVALID => [ + 'name' => Exception::DOMAIN_TARGET_INVALID, 'description' => 'Your Appwrite instance is not publicly accessible. Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.', 'code' => 501, ], diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index bc57cf04ac..deff177ab2 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1340,7 +1340,7 @@ App::post('/v1/projects/:projectId/domains') $target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', '')); if (!$target->isKnown() || $target->isTest()) { - throw new Exception(Exception::DOMAIN_VARIABLE_INCORRECT, 'Unreachable CNAME target (' . $target->get() . '). Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.'); + throw new Exception(Exception::DOMAIN_TARGET_INVALID, 'Unreachable CNAME target (' . $target->get() . '). Please check the _APP_DOMAIN_TARGET environment variable of your Appwrite server.'); } $domain = new Domain($domain); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index fda96b4bcd..9e2e8f9cb1 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -177,7 +177,7 @@ class Exception extends \Exception public const DOMAIN_NOT_FOUND = 'domain_not_found'; public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists'; public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed'; - public const DOMAIN_VARIABLE_INCORRECT = 'domain_variable_incorrect'; + public const DOMAIN_TARGET_INVALID = 'domain_target_invalid'; /** GraphqQL */ public const GRAPHQL_NO_QUERY = 'graphql_no_query';