From 0ecf75cbdb74749e1821eb62313fce22a61decbe Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Mon, 13 Jan 2025 23:18:24 +0800 Subject: [PATCH] misc: scoped down to AWS-related errors --- .../services/external-kms/external-kms-service.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/ee/services/external-kms/external-kms-service.ts b/backend/src/ee/services/external-kms/external-kms-service.ts index 27781cf56..faaace343 100644 --- a/backend/src/ee/services/external-kms/external-kms-service.ts +++ b/backend/src/ee/services/external-kms/external-kms-service.ts @@ -1,3 +1,5 @@ +import { KMSServiceException } from "@aws-sdk/client-kms"; +import { STSServiceException } from "@aws-sdk/client-sts"; import { ForbiddenError } from "@casl/ability"; import slugify from "@sindresorhus/slugify"; @@ -71,10 +73,14 @@ export const externalKmsServiceFactory = ({ switch (provider.type) { case KmsProviders.Aws: { - const externalKms = await AwsKmsProviderFactory({ inputs: provider.inputs }).catch((error: Error) => { - throw new InternalServerError({ - message: error.message ? `AWS error: ${error.message}` : "" - }); + const externalKms = await AwsKmsProviderFactory({ inputs: provider.inputs }).catch((error) => { + if (error instanceof STSServiceException || error instanceof KMSServiceException) { + throw new InternalServerError({ + message: error.message ? `AWS error: ${error.message}` : "" + }); + } + + throw error; }); // if missing kms key this generate a new kms key id and returns new provider input