From d977092502896b6e2b82900eff094372aebfa317 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Fri, 25 Apr 2025 15:05:22 -0700 Subject: [PATCH 1/2] improvement: improve validate aws connection error propagation --- .../app-connection/aws/aws-connection-fns.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.ts b/backend/src/services/app-connection/aws/aws-connection-fns.ts index 767cb82fb..93d858c32 100644 --- a/backend/src/services/app-connection/aws/aws-connection-fns.ts +++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts @@ -1,9 +1,11 @@ import { AssumeRoleCommand, STSClient } from "@aws-sdk/client-sts"; import AWS from "aws-sdk"; +import { AxiosError } from "axios"; import { randomUUID } from "crypto"; import { getConfig } from "@app/lib/config/env"; import { BadRequestError, InternalServerError } from "@app/lib/errors"; +import { logger } from "@app/lib/logger"; import { AppConnection, AWSRegion } from "@app/services/app-connection/app-connection-enums"; import { AwsConnectionMethod } from "./aws-connection-enums"; @@ -90,9 +92,20 @@ export const validateAwsConnectionCredentials = async (appConnection: TAwsConnec const sts = new AWS.STS(awsConfig); resp = await sts.getCallerIdentity().promise(); - } catch (e: unknown) { + } catch (error: unknown) { + logger.error(error, "Error validating AWS connection credentials"); + + let message: string; + + if (error instanceof AxiosError) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + message = (error.response?.data?.message as string) || error.message; + } else { + message = (error as Error)?.message || "verify credentials"; + } + throw new BadRequestError({ - message: `Unable to validate connection: verify credentials` + message: `Unable to validate connection: ${message}` }); } From fa8154ecddd1870616dd155d0a7dd829369d3ea7 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Fri, 25 Apr 2025 15:06:16 -0700 Subject: [PATCH 2/2] improvement: add undefined handling --- backend/src/services/app-connection/aws/aws-connection-fns.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.ts b/backend/src/services/app-connection/aws/aws-connection-fns.ts index 93d858c32..28660173b 100644 --- a/backend/src/services/app-connection/aws/aws-connection-fns.ts +++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts @@ -99,7 +99,7 @@ export const validateAwsConnectionCredentials = async (appConnection: TAwsConnec if (error instanceof AxiosError) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - message = (error.response?.data?.message as string) || error.message; + message = (error.response?.data?.message as string) || error.message || "verify credentials"; } else { message = (error as Error)?.message || "verify credentials"; }