diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts index bb24c9d78..4d8365276 100644 --- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts +++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts @@ -1105,9 +1105,9 @@ export const secretV2BridgeServiceFactory = ({ if (shouldExpandSecretReferences) { const secretsGroupByPath = groupBy(decryptedSecrets, (i) => i.secretPath); - await Promise.all( + const settledPromises = await Promise.allSettled( Object.keys(secretsGroupByPath).map((groupedPath) => - Promise.all( + Promise.allSettled( secretsGroupByPath[groupedPath].map(async (decryptedSecret, index) => { const expandedSecretValue = await expandSecretReferences({ value: decryptedSecret.secretValue, @@ -1121,6 +1121,34 @@ export const secretV2BridgeServiceFactory = ({ ) ) ); + const errors: { path: string; error: string }[] = []; + + settledPromises.forEach((outerResult: PromiseSettledResult[]>, outerIndex) => { + const groupedPath = Object.keys(secretsGroupByPath)[outerIndex]; + + if (outerResult.status === "rejected") { + errors.push({ + path: groupedPath, + error: `Failed to process secret group: ${outerResult.reason}` + }); + } else { + // Check inner promise results + outerResult.value.forEach((innerResult: PromiseSettledResult) => { + if (innerResult.status === "rejected") { + errors.push({ + path: groupedPath, + error: `Failed to expand secret reference: ${innerResult.reason}` + }); + } + }); + } + }); + if (errors.length > 0) { + throw new ForbiddenRequestError({ + message: "Failed to expand one or more secret references", + details: errors.map((err) => err.error) + }); + } } if (!includeImports) {