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 3f105484e1..87a9c420c7 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -270,7 +270,11 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } if ($deployment->getAttribute('status') !== 'ready') { - throw new AppwriteException(AppwriteException::BUILD_NOT_READY); + if ($deployment->getAttribute('status') === 'failed') { + throw new AppwriteException(AppwriteException::BUILD_FAILED); + } else { + throw new AppwriteException(AppwriteException::BUILD_NOT_READY); + } } if ($type === 'function') { 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'; diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index d0cc3b5ba5..bf9eb0dc29 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2393,4 +2393,41 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testDomainForFailedDeloyment(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Test Site', + 'framework' => 'astro', + 'buildRuntime' => 'node-22', + 'buildCommand' => 'cd random' + ]); + + $this->assertNotEmpty($siteId); + + $domain = $this->setupSiteDomain($siteId); + $this->assertNotEmpty($domain); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $deployment = $this->createDeployment($siteId, [ + 'code' => $this->packageSite('astro'), + 'activate' => true + ]); + $this->assertEquals(202, $deployment['headers']['status-code']); + + $deploymentId = $deployment['body']['$id']; + $this->assertNotEmpty($deploymentId); + + $this->assertEventually(function () use ($siteId, $deploymentId) { + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals('failed', $deployment['body']['status'], json_encode($deployment['body'], JSON_PRETTY_PRINT)); + }, 100000, 500); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertStringContainsString('build_failed', $response['body']); + + $this->cleanupSite($siteId); + } }