From 8139ec0d6fdecc2d8d833d5637dbcd81a328edf4 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Thu, 3 Apr 2025 18:49:41 +0530 Subject: [PATCH] Add more error pages --- app/config/errors.php | 5 +++++ app/controllers/general.php | 13 ++++++++++++- app/views/general/error.phtml | 26 ++++++++++++++++++++++++-- src/Appwrite/Extend/Exception.php | 1 + 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index f9c2f6b5ba..8847ff7c42 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_CANCELED => [ + 'name' => Exception::BUILD_CANCELED, + 'description' => 'Build with the requested ID has been canceled.', + 'code' => 400, + ], Exception::BUILD_FAILED => [ 'name' => Exception::BUILD_FAILED, 'description' => 'Build with the requested ID failed. Please check the logs for more information.', diff --git a/app/controllers/general.php b/app/controllers/general.php index f671c97183..62a83cf3a6 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -139,6 +139,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw /** @var Database $dbForProject */ $dbForProject = $getProjectDB($project); + /** @var Document $deployment */ $deployment = Authorization::skip(fn () => $dbForProject->getDocument('deployments', $rule->getAttribute('deploymentId'))); if ($deployment->getAttribute('resourceType', '') === 'functions') { @@ -147,6 +148,10 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $type = 'site'; } + if ($deployment->isEmpty()) { + throw new AppwriteException(AppwriteException::DEPLOYMENT_NOT_FOUND); + } + $resource = $type === 'function' ? Authorization::skip(fn () => $dbForProject->getDocument('functions', $deployment->getAttribute('resourceId', ''))) : Authorization::skip(fn () => $dbForProject->getDocument('sites', $deployment->getAttribute('resourceId', ''))); @@ -239,7 +244,11 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $requestHeaders = $request->getHeaders(); if ($resource->isEmpty() || !$resource->getAttribute('enabled')) { - throw new AppwriteException(AppwriteException::FUNCTION_NOT_FOUND); + if ($type === 'functions') { + throw new AppwriteException(AppwriteException::FUNCTION_NOT_FOUND); + } else { + throw new AppwriteException(AppwriteException::SITE_NOT_FOUND); + } } if ($isResourceBlocked($project, $type === 'function' ? RESOURCE_TYPE_FUNCTIONS : RESOURCE_TYPE_SITES, $resource->getId())) { @@ -273,6 +282,8 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw if (!$allowAnyStatus && $deployment->getAttribute('status') !== 'ready') { if ($deployment->getAttribute('status') === 'failed') { throw new AppwriteException(AppwriteException::BUILD_FAILED); + } elseif ($deployment->getAttribute('status') === 'canceled') { + throw new AppwriteException(AppwriteException::BUILD_CANCELED); } else { throw new AppwriteException(AppwriteException::BUILD_NOT_READY); } diff --git a/app/views/general/error.phtml b/app/views/general/error.phtml index f36f1957e7..b80d0f61cd 100644 --- a/app/views/general/error.phtml +++ b/app/views/general/error.phtml @@ -9,7 +9,7 @@ $projectName = $this->getParam('projectName', ''); $projectURL = $this->getParam('projectURL', ''); $title = $this->getParam('title', 'Error'); -$knownTypes = ['build_not_ready', 'build_failed', 'rule_not_found']; +$knownTypes = ['build_not_ready', 'build_failed', 'rule_not_found', 'deployment_not_found', 'build_canceled']; $label = ''; $labelClass = ''; $buttons = []; @@ -55,6 +55,28 @@ switch ($type) { ], ]; break; + case 'deployment_not_found': + $label = 'No deployments available'; + $message = 'This page is empty, deploy your site to make it live.'; + $buttons = [ + [ + 'text' => 'View deployments', + 'url' => '/', + 'class' => 'bordered-button' + ], + ]; + break; + case 'build_canceled': + $label = 'Deployment build cancelled'; + $message = 'The build process was cancelled.'; + $buttons = [ + [ + 'text' => 'View deployments', + 'url' => '/', + 'class' => 'bordered-button' + ], + ]; + break; default: $label = 'Error ' . $code; $message = $message; @@ -316,7 +338,7 @@ switch ($type) { - + print($type); ?> diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 338da29403..f137725eaf 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_CANCELED = 'build_canceled'; public const BUILD_FAILED = 'build_failed'; /** Execution */