From 31c38db1518dd3dd24d30a02f04bcbdfac0f3381 Mon Sep 17 00:00:00 2001 From: "Lingling Ye (from Dev Box)" Date: Fri, 10 Jul 2026 18:10:30 +0800 Subject: [PATCH] refactor --- src/appConfigurationImpl.ts | 9 +++++---- src/common/utils.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/appConfigurationImpl.ts b/src/appConfigurationImpl.ts index e247b314..a3d4834e 100644 --- a/src/appConfigurationImpl.ts +++ b/src/appConfigurationImpl.ts @@ -60,6 +60,7 @@ import { AIConfigurationTracingOptions } from "./requestTracing/aiConfigurationT import { KeyFilter, LabelFilter, SettingWatcher, SettingSelector, PagedSettingsWatcher, WatchedSetting } from "./types.js"; import { ConfigurationClientManager } from "./configurationClientManager.js"; import { getFixedBackoffDuration, getExponentialBackoffDuration } from "./common/backoffUtils.js"; +import { getStatusCode } from "./common/utils.js"; import { InvalidOperationError, ArgumentError, isFailoverableError, isInputError, SnapshotReferenceError } from "./common/errors.js"; import { ErrorMessages } from "./common/errorMessages.js"; @@ -659,7 +660,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { const watcher: SettingWatcher = this.#sentinels.get(watchedSetting)!; // watcher should always exist for sentinels const isDeleted = response === undefined && watcher.etag !== undefined; // previously existed, now deleted - const isChanged = response && Number(response.statusCode) === 200 && watcher.etag !== response.etag; // etag changed + const isChanged = response && getStatusCode(response.statusCode) === 200 && watcher.etag !== response.etag; // etag changed if (isDeleted || isChanged) { changedSentinel = watchedSetting; changedSentinelWatcher = { etag: isChanged ? response.etag : undefined }; @@ -750,7 +751,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { for await (const page of pageIterator) { // when conditional request is sent, the response will be 304 if not changed - if (Number(page._response.status) === 200) { // created or changed + if (getStatusCode(page._response.status) === 200) { // created or changed return true; } } @@ -779,7 +780,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { try { response = await this.#executeWithFailoverPolicy(funcToExecute); } catch (error) { - if (isRestError(error) && Number(error.statusCode) === 404) { + if (isRestError(error) && getStatusCode(error.statusCode) === 404) { response = undefined; } else { throw error; @@ -822,7 +823,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { try { response = await this.#executeWithFailoverPolicy(funcToExecute); } catch (error) { - if (isRestError(error) && Number(error.statusCode) === 404) { + if (isRestError(error) && getStatusCode(error.statusCode) === 404) { response = undefined; } else { throw error; diff --git a/src/common/utils.ts b/src/common/utils.ts index 18667874..9685c6ce 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -12,3 +12,15 @@ export function shuffleList(array: T[]): T[] { export function instanceOfTokenCredential(obj: unknown) { return obj && typeof obj === "object" && "getToken" in obj && typeof obj.getToken === "function"; } + +/** + * Normalizes an HTTP status code to a number. + * + * The underlying App Configuration client may surface the status code either as a number + * or as a string (e.g. "200", "304", "404") depending on the runtime/transport. This helper + * coerces the value to a number so that status code comparisons behave consistently and + * refresh logic is not broken when the status is a string. + */ +export function getStatusCode(statusCode: number | string | undefined): number { + return Number(statusCode); +}