Skip to content

Commit 09316af

Browse files
committed
fix(signature-v4-multi-region): add check for node and error messages
1 parent b3ce48a commit 09316af

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

packages/signature-v4-multi-region/src/SignatureV4MultiRegion.ts

+35-35
Original file line numberDiff line numberDiff line change
@@ -78,49 +78,49 @@ export class SignatureV4MultiRegion implements RequestPresigner, RequestSigner {
7878

7979
private getSigv4aSigner(): InstanceType<OptionalCrtSignerV4> | InstanceType<OptionalSigV4aSigner> {
8080
if (!this.sigv4aSigner) {
81-
let CrtSignerV4: OptionalCrtSignerV4 | null = null;
82-
let JsSigV4aSigner: OptionalSigV4aSigner | null = null;
81+
const CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
82+
const JsSigV4aSigner = signatureV4aContainer.SignatureV4a;
8383

84-
if (signatureV4CrtContainer.CrtSignerV4) {
85-
try {
86-
CrtSignerV4 = signatureV4CrtContainer.CrtSignerV4;
87-
if (typeof CrtSignerV4 !== "function") throw new Error();
88-
} catch (e) {
89-
e.message =
90-
`${e.message}\n` +
91-
`Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. \n` +
92-
`You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] ` +
93-
`or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. \n` +
94-
"For more information please go to " +
95-
"https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt";
96-
throw e;
84+
if (this.signerOptions.runtime === "node") {
85+
if (!CrtSignerV4 && !JsSigV4aSigner) {
86+
throw new Error(
87+
"Neither CRT nor JS SigV4a implementation is available. " +
88+
"Please load either @aws-sdk/signature-v4-crt or @smithy/signature-v4a. " +
89+
"For more information please go to " +
90+
"https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt"
91+
);
9792
}
9893

99-
this.sigv4aSigner = new CrtSignerV4({
100-
...this.signerOptions,
101-
signingAlgorithm: 1,
102-
});
103-
} else if (signatureV4aContainer.SignatureV4a) {
104-
try {
105-
JsSigV4aSigner = signatureV4aContainer.SignatureV4a;
106-
if (typeof JsSigV4aSigner !== "function") throw new Error();
107-
} catch (e) {
108-
e.message =
109-
`${e.message}\n` +
110-
`Please check whether you have installed the "@smithy/signature-v4a" package explicitly. \n` +
111-
`You must also register the package by calling [require("@smithy/signature-v4a");] ` +
112-
`or an ESM equivalent such as [import "@smithy/signature-v4a";]. \n`;
113-
throw e;
94+
if (CrtSignerV4 && typeof CrtSignerV4 === "function") {
95+
this.sigv4aSigner = new CrtSignerV4({
96+
...this.signerOptions,
97+
signingAlgorithm: 1,
98+
});
99+
} else if (JsSigV4aSigner && typeof JsSigV4aSigner === "function") {
100+
this.sigv4aSigner = new JsSigV4aSigner({
101+
...this.signerOptions,
102+
});
103+
} else {
104+
throw new Error(
105+
"Available SigV4a implementation is not a valid constructor. " +
106+
"Please ensure you've properly imported @aws-sdk/signature-v4-crt or @smithy/signature-v4a."
107+
);
108+
}
109+
} else {
110+
if (!JsSigV4aSigner || typeof JsSigV4aSigner !== "function") {
111+
throw new Error(
112+
"JS SigV4a implementation is not available or not a valid constructor. " +
113+
"Please check whether you have installed the @smithy/signature-v4a package explicitly. " +
114+
"You must also register the package by calling [require('@smithy/signature-v4a');] " +
115+
"or an ESM equivalent such as [import '@smithy/signature-v4a';]. " +
116+
"For more information please go to " +
117+
"https://github.com/aws/aws-sdk-js-v3#using-javascript-non-crt-implementation-of-sigv4a"
118+
);
114119
}
115120

116121
this.sigv4aSigner = new JsSigV4aSigner({
117122
...this.signerOptions,
118123
});
119-
} else {
120-
throw new Error(
121-
"Neither CRT nor JS SigV4a implementation is available. " +
122-
"Please load either @aws-sdk/signature-v4-crt or @smithy/signature-v4a."
123-
);
124124
}
125125
}
126126
return this.sigv4aSigner;

0 commit comments

Comments
 (0)