Skip to content

Commit eb0e23f

Browse files
Merge branch 'main' into linglingye/dedup-key-vault-ref
2 parents adb6155 + 4f6d8b3 commit eb0e23f

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/appConfigurationImpl.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { AIConfigurationTracingOptions } from "./requestTracing/aiConfigurationT
6060
import { KeyFilter, LabelFilter, SettingWatcher, SettingSelector, PagedSettingsWatcher, WatchedSetting } from "./types.js";
6161
import { ConfigurationClientManager } from "./configurationClientManager.js";
6262
import { getFixedBackoffDuration, getExponentialBackoffDuration } from "./common/backoffUtils.js";
63+
import { getStatusCode } from "./common/utils.js";
6364
import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError, SnapshotReferenceError } from "./common/errors.js";
6465
import { ErrorMessages } from "./common/errorMessages.js";
6566

@@ -654,7 +655,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
654655

655656
const watcher: SettingWatcher = this.#sentinels.get(watchedSetting)!; // watcher should always exist for sentinels
656657
const isDeleted = response === undefined && watcher.etag !== undefined; // previously existed, now deleted
657-
const isChanged = response && Number(response.statusCode) === 200 && watcher.etag !== response.etag; // etag changed
658+
const isChanged = response && getStatusCode(response.statusCode) === 200 && watcher.etag !== response.etag; // etag changed
658659
if (isDeleted || isChanged) {
659660
changedSentinel = watchedSetting;
660661
changedSentinelWatcher = { etag: isChanged ? response.etag : undefined };
@@ -752,7 +753,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
752753

753754
for await (const page of pageIterator) {
754755
// when conditional request is sent, the response will be 304 if not changed
755-
if (Number(page._response.status) === 200) { // created or changed
756+
if (getStatusCode(page._response.status) === 200) { // created or changed
756757
return true;
757758
}
758759
}
@@ -781,7 +782,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
781782
try {
782783
response = await this.#executeWithFailoverPolicy(funcToExecute);
783784
} catch (error) {
784-
if (isRestError(error) && Number(error.statusCode) === 404) {
785+
if (isRestError(error) && getStatusCode(error.statusCode) === 404) {
785786
response = undefined;
786787
} else {
787788
throw error;
@@ -824,7 +825,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
824825
try {
825826
response = await this.#executeWithFailoverPolicy(funcToExecute);
826827
} catch (error) {
827-
if (isRestError(error) && Number(error.statusCode) === 404) {
828+
if (isRestError(error) && getStatusCode(error.statusCode) === 404) {
828829
response = undefined;
829830
} else {
830831
throw error;

src/common/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ export function shuffleList<T>(array: T[]): T[] {
1212
export function instanceOfTokenCredential(obj: unknown) {
1313
return obj && typeof obj === "object" && "getToken" in obj && typeof obj.getToken === "function";
1414
}
15+
16+
/**
17+
* Normalizes an HTTP status code to a number.
18+
*
19+
* The underlying App Configuration client may surface the status code either as a number
20+
* or as a string (e.g. "200", "304", "404") depending on the runtime/transport. This helper
21+
* coerces the value to a number so that status code comparisons behave consistently and
22+
* refresh logic is not broken when the status is a string.
23+
*/
24+
export function getStatusCode(statusCode: number | string | undefined): number {
25+
return Number(statusCode);
26+
}

0 commit comments

Comments
 (0)