Skip to content

Commit 191326f

Browse files
committed
throw exception directly during input validation
1 parent 1020a06 commit 191326f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/load.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ async function loadPromise(
4848
credentialOrOptions?: TokenCredential | AzureAppConfigurationOptions,
4949
appConfigOptions?: AzureAppConfigurationOptions
5050
): Promise<AzureAppConfiguration> {
51+
const startTimestamp = Date.now();
5152
let client: AppConfigurationClient;
5253
let options: AzureAppConfigurationOptions | undefined;
54+
55+
// input validation
5356
if (typeof connectionStringOrEndpoint === "string" && !instanceOfTokenCredential(credentialOrOptions)) {
5457
const connectionString = connectionStringOrEndpoint;
5558
options = credentialOrOptions as AzureAppConfigurationOptions;
@@ -77,9 +80,20 @@ async function loadPromise(
7780
throw new Error("A connection string or an endpoint with credential must be specified to create a client.");
7881
}
7982

80-
const appConfiguration = new AzureAppConfigurationImpl(client, options);
81-
await appConfiguration.load();
82-
return appConfiguration;
83+
try {
84+
const appConfiguration = new AzureAppConfigurationImpl(client, options);
85+
await appConfiguration.load();
86+
return appConfiguration;
87+
} catch (error) {
88+
// load() method is called in the application's startup code path.
89+
// Unhandled exceptions cause application crash which can result in crash loops as orchestrators attempt to restart the application.
90+
// Knowing the intended usage of the provider in startup code path, we mitigate back-to-back crash loops from overloading the server with requests by waiting a minimum time to propagate fatal errors.
91+
const delay = MinDelayForUnhandedError - (Date.now() - startTimestamp);
92+
if (delay > 0) {
93+
await new Promise((resolve) => setTimeout(resolve, delay));
94+
}
95+
throw error;
96+
}
8397
}
8498

8599
function instanceOfTokenCredential(obj: unknown) {

0 commit comments

Comments
 (0)