|
6 | 6 | import { env } from "~/env.server"; |
7 | 7 | import { authenticateApiRequest } from "~/services/apiAuth.server"; |
8 | 8 | import { logger } from "~/services/logger.server"; |
| 9 | +import { ServiceValidationError } from "~/v3/services/baseService.server"; |
9 | 10 | import { InitializeDeploymentService } from "~/v3/services/initializeDeployment.server"; |
10 | 11 |
|
11 | 12 | export async function action({ request, params }: ActionFunctionArgs) { |
@@ -33,18 +34,30 @@ export async function action({ request, params }: ActionFunctionArgs) { |
33 | 34 |
|
34 | 35 | const service = new InitializeDeploymentService(); |
35 | 36 |
|
36 | | - const { deployment, imageTag } = await service.call(authenticatedEnv, body.data); |
37 | | - |
38 | | - const responseBody: InitializeDeploymentResponseBody = { |
39 | | - id: deployment.friendlyId, |
40 | | - contentHash: deployment.contentHash, |
41 | | - shortCode: deployment.shortCode, |
42 | | - version: deployment.version, |
43 | | - externalBuildData: |
44 | | - deployment.externalBuildData as InitializeDeploymentResponseBody["externalBuildData"], |
45 | | - imageTag, |
46 | | - registryHost: body.data.registryHost ?? env.DEPLOY_REGISTRY_HOST, |
47 | | - }; |
48 | | - |
49 | | - return json(responseBody, { status: 200 }); |
| 37 | + try { |
| 38 | + const { deployment, imageTag } = await service.call(authenticatedEnv, body.data); |
| 39 | + |
| 40 | + const responseBody: InitializeDeploymentResponseBody = { |
| 41 | + id: deployment.friendlyId, |
| 42 | + contentHash: deployment.contentHash, |
| 43 | + shortCode: deployment.shortCode, |
| 44 | + version: deployment.version, |
| 45 | + externalBuildData: |
| 46 | + deployment.externalBuildData as InitializeDeploymentResponseBody["externalBuildData"], |
| 47 | + imageTag, |
| 48 | + registryHost: body.data.registryHost ?? env.DEPLOY_REGISTRY_HOST, |
| 49 | + }; |
| 50 | + |
| 51 | + return json(responseBody, { status: 200 }); |
| 52 | + } catch (error) { |
| 53 | + if (error instanceof ServiceValidationError) { |
| 54 | + return json({ error: error.message }, { status: 400 }); |
| 55 | + } else if (error instanceof Error) { |
| 56 | + logger.error("Error initializing deployment", { error: error.message }); |
| 57 | + return json({ error: `Internal server error: ${error.message}` }, { status: 500 }); |
| 58 | + } else { |
| 59 | + logger.error("Error initializing deployment", { error: String(error) }); |
| 60 | + return json({ error: "Internal server error" }, { status: 500 }); |
| 61 | + } |
| 62 | + } |
50 | 63 | } |
0 commit comments