Skip to content

Commit 3afb300

Browse files
update
1 parent aa037e5 commit 3afb300

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/error.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT license.
33

44
import { isRestError } from "@azure/core-rest-pipeline";
5+
import { AuthenticationError } from "@azure/identity";
6+
57

68
/**
79
* Error thrown when an operation cannot be performed by the Azure App Configuration provider.
@@ -27,13 +29,16 @@ export class ArgumentError extends Error {
2729
* Error thrown when a Key Vault reference cannot be resolved.
2830
*/
2931
export class KeyVaultReferenceError extends Error {
30-
constructor(message: string) {
31-
super(message);
32+
constructor(message: string, options?: ErrorOptions) {
33+
super(message, options);
3234
this.name = "KeyVaultReferenceError";
3335
}
3436
}
3537

3638
export function isFailoverableError(error: any): boolean {
39+
if (error instanceof AuthenticationError) {
40+
return true;
41+
}
3742
if (!isRestError(error)) {
3843
return false;
3944
}

src/keyvault/AzureKeyVaultKeyValueAdapter.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ export class AzureKeyVaultKeyValueAdapter implements IKeyValueAdapter {
2727
if (!this.#keyVaultOptions) {
2828
throw new ArgumentError("Failed to process the Key Vault reference because Key Vault options are not configured.");
2929
}
30-
31-
const { name: secretName, vaultUrl, sourceId, version } = parseKeyVaultSecretIdentifier(
32-
parseSecretReference(setting).value.secretId
33-
);
30+
let sourceId;
3431
try {
32+
const { name: secretName, vaultUrl, sourceId: parsedSourceId, version } = parseKeyVaultSecretIdentifier(
33+
parseSecretReference(setting).value.secretId
34+
);
35+
sourceId = parsedSourceId;
3536
// precedence: secret clients > credential > secret resolver
3637
const client = this.#getSecretClient(new URL(vaultUrl));
3738
if (client) {
@@ -42,7 +43,7 @@ export class AzureKeyVaultKeyValueAdapter implements IKeyValueAdapter {
4243
return [setting.key, await this.#keyVaultOptions.secretResolver(new URL(sourceId))];
4344
}
4445
} catch (error) {
45-
throw new KeyVaultReferenceError(buildKeyVaultReferenceErrorMessage(error.message, setting, sourceId));
46+
throw new KeyVaultReferenceError(buildKeyVaultReferenceErrorMessage(setting, sourceId), { cause: error });
4647
}
4748

4849
// When code reaches here, it means that the key vault reference cannot be resolved in all possible ways.
@@ -79,6 +80,6 @@ export class AzureKeyVaultKeyValueAdapter implements IKeyValueAdapter {
7980
}
8081
}
8182

82-
function buildKeyVaultReferenceErrorMessage(message: string, setting: ConfigurationSetting, secretIdentifier?: string ): string {
83-
return `${message} Key: '${setting.key}' Label: '${setting.label ?? ""}' ETag: '${setting.etag ?? ""}' SecretIdentifier: '${secretIdentifier ?? ""}'`;
83+
function buildKeyVaultReferenceErrorMessage(setting: ConfigurationSetting, secretIdentifier?: string ): string {
84+
return `Failed to resolve Key Vault reference. Key: '${setting.key}' Label: '${setting.label ?? ""}' ETag: '${setting.etag ?? ""}' SecretIdentifier: '${secretIdentifier ?? ""}'`;
8485
}

0 commit comments

Comments
 (0)