Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/appConfigurationImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ export function shuffleList<T>(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);
}
Loading