From bd18edc197af640253bc58cbf668ed2491c7d352 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 24 Mar 2025 15:50:25 +0530 Subject: [PATCH] If build has failed, show correct error page --- app/config/errors.php | 5 +++++ app/controllers/general.php | 6 +++++- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index 58e95cf5d4..c3b791f613 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -580,6 +580,11 @@ return [ 'description' => 'Build with the requested ID is already completed and cannot be canceled.', 'code' => 400, ], + Exception::BUILD_FAILED => [ + 'name' => Exception::BUILD_FAILED, + 'description' => 'Build with the requested ID failed. Please check the logs for more information.', + 'code' => 400, + ], /** Deployments */ Exception::DEPLOYMENT_NOT_FOUND => [ diff --git a/app/controllers/general.php b/app/controllers/general.php index 3afe1d8a3d..c378ba817a 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -269,10 +269,14 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw throw new AppwriteException(AppwriteException::FUNCTION_RUNTIME_UNSUPPORTED, 'Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported'); } - if ($deployment->getAttribute('status') !== 'ready') { + if ($deployment->getAttribute('status') === 'waiting' || $deployment->getAttribute('status') === 'processing' || $deployment->getAttribute('status') === 'building') { throw new AppwriteException(AppwriteException::BUILD_NOT_READY); } + if ($deployment->getAttribute('status') === 'failed') { + throw new AppwriteException(AppwriteException::BUILD_FAILED); + } + if ($type === 'function') { $permissions = $resource->getAttribute('execute'); if (!(\in_array('any', $permissions)) && !(\in_array('guests', $permissions))) { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index db8f5f7134..338da29403 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -174,6 +174,7 @@ class Exception extends \Exception public const BUILD_NOT_READY = 'build_not_ready'; public const BUILD_IN_PROGRESS = 'build_in_progress'; public const BUILD_ALREADY_COMPLETED = 'build_already_completed'; + public const BUILD_FAILED = 'build_failed'; /** Execution */ public const EXECUTION_NOT_FOUND = 'execution_not_found';