Add more error pages

This commit is contained in:
Khushboo Verma
2025-04-03 18:49:41 +05:30
parent 5841d5ee57
commit 8139ec0d6f
4 changed files with 42 additions and 3 deletions
+5
View File
@@ -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.',
+12 -1
View File
@@ -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);
}
+24 -2
View File
@@ -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) {
</a>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!in_array($type, ['build_not_ready', 'build_failed', 'rule_not_found'])): ?>
<?php if (!in_array($type, $knownTypes)): ?>
<span class='type'><?php echo $this->print($type); ?></span>
<?php endif; ?>
</div>
+1
View File
@@ -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 */