Skip to content

Commit 210984a

Browse files
committed
missing tryCatch for sts call
1 parent ba68d19 commit 210984a

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

apps/webapp/app/v3/getDeploymentImageRef.server.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ async function getAssumedRoleCredentials({
3636
const randomSuffix = Math.random().toString(36).substring(2, 8);
3737
const sessionName = `TriggerWebappECRAccess_${timestamp}_${randomSuffix}`;
3838

39-
try {
40-
const response = await sts.send(
39+
const [error, response] = await tryCatch(
40+
sts.send(
4141
new AssumeRoleCommand({
4242
RoleArn: assumeRole?.roleArn,
4343
RoleSessionName: sessionName,
@@ -46,33 +46,35 @@ async function getAssumedRoleCredentials({
4646
DurationSeconds: 3600,
4747
ExternalId: assumeRole?.externalId,
4848
})
49-
);
50-
51-
if (!response.Credentials) {
52-
throw new Error("STS: No credentials returned from assumed role");
53-
}
54-
55-
if (
56-
!response.Credentials.AccessKeyId ||
57-
!response.Credentials.SecretAccessKey ||
58-
!response.Credentials.SessionToken
59-
) {
60-
throw new Error("STS: Invalid credentials returned from assumed role");
61-
}
49+
)
50+
);
6251

63-
return {
64-
accessKeyId: response.Credentials.AccessKeyId,
65-
secretAccessKey: response.Credentials.SecretAccessKey,
66-
sessionToken: response.Credentials.SessionToken,
67-
};
68-
} catch (error) {
52+
if (error) {
6953
logger.error("Failed to assume role", {
7054
assumeRole,
7155
sessionName,
72-
error,
56+
error: error.message,
7357
});
7458
throw error;
7559
}
60+
61+
if (!response.Credentials) {
62+
throw new Error("STS: No credentials returned from assumed role");
63+
}
64+
65+
if (
66+
!response.Credentials.AccessKeyId ||
67+
!response.Credentials.SecretAccessKey ||
68+
!response.Credentials.SessionToken
69+
) {
70+
throw new Error("STS: Invalid credentials returned from assumed role");
71+
}
72+
73+
return {
74+
accessKeyId: response.Credentials.AccessKeyId,
75+
secretAccessKey: response.Credentials.SecretAccessKey,
76+
sessionToken: response.Credentials.SessionToken,
77+
};
7678
}
7779

7880
export async function createEcrClient({

0 commit comments

Comments
 (0)