The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix error handling in serverless service (#6442)
martmullfb0fd99a3855
diff --git a/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.ts b/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.tsindex 241744b9212..9820aa8d8b8 100644--- a/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.ts+++ b/packages/twenty-server/src/engine/integrations/serverless/drivers/lambda.driver.ts@@ -8,6 +8,7 @@ import {GetFunctionCommand,UpdateFunctionCodeCommand,DeleteFunctionCommand,+ ResourceNotFoundException,} from '@aws-sdk/client-lambda';import { CreateFunctionCommandInput } from '@aws-sdk/client-lambda/dist-types/commands/CreateFunctionCommand';import { UpdateFunctionCodeCommandInput } from '@aws-sdk/client-lambda/dist-types/commands/UpdateFunctionCodeCommand';@@ -46,15 +47,36 @@ export class LambdaDriverthis.buildDirectoryManagerService = options.buildDirectoryManagerService;}- async delete(serverlessFunction: ServerlessFunctionEntity) {+ private async checkFunctionExists(+ serverlessFunctionId: string,+ ): Promise<boolean> {try {+ const getFunctionCommand = new GetFunctionCommand({+ FunctionName: serverlessFunctionId,+ });++ await this.lambdaClient.send(getFunctionCommand);++ return true;+ } catch (error) {+ if (error instanceof ResourceNotFoundException) {+ return false;+ }+ throw error;+ }+ }++ async delete(serverlessFunction: ServerlessFunctionEntity) {+ const functionExists = await this.checkFunctionExists(+ serverlessFunction.id,+ );++ if (functionExists) {const deleteFunctionCommand = new DeleteFunctionCommand({FunctionName: serverlessFunction.id,});await this.lambdaClient.send(deleteFunctionCommand);- } catch {- return;}}@@ -75,19 +97,11 @@ export class LambdaDriverawait createZipFile(sourceTemporaryDir, lambdaZipPath);- let existingFunction = true;-- try {- const getFunctionCommand = new GetFunctionCommand({- FunctionName: serverlessFunction.id,- });-- await this.lambdaClient.send(getFunctionCommand);- } catch {- existingFunction = false;- }+ const functionExists = await this.checkFunctionExists(+ serverlessFunction.id,+ );- if (!existingFunction) {+ if (!functionExists) {const params: CreateFunctionCommandInput = {Code: {ZipFile: await fs.promises.readFile(lambdaZipPath),diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.tsindex 7a145c631b1..df293846c48 100644--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function.dto.ts@@ -48,7 +48,7 @@ export class ServerlessFunctionDto {name: string;@IsString()- @Field()+ @Field({ nullable: true })description: string;@IsString()