mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-07-16 00:43:49 +01:00
add timeout for ARM calls
This commit is contained in:
parent
e406bf8190
commit
58aff4f07b
@ -35,6 +35,25 @@ import { QueryCopilotState, useQueryCopilot } from "hooks/useQueryCopilot";
|
|||||||
import { useTabs } from "hooks/useTabs";
|
import { useTabs } from "hooks/useTabs";
|
||||||
import * as StringUtility from "../../../Shared/StringUtility";
|
import * as StringUtility from "../../../Shared/StringUtility";
|
||||||
|
|
||||||
|
async function fetchWithTimeout(url: string, headers: {
|
||||||
|
[x: string]: string;
|
||||||
|
}) {
|
||||||
|
const timeout = 8000;
|
||||||
|
const options = { timeout };
|
||||||
|
|
||||||
|
const controller = new AbortController();
|
||||||
|
const id = setTimeout(() => controller.abort(), timeout);
|
||||||
|
|
||||||
|
const response = await window.fetch(url, {
|
||||||
|
headers,
|
||||||
|
...options,
|
||||||
|
signal: controller.signal
|
||||||
|
});
|
||||||
|
clearTimeout(id);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
export const isCopilotFeatureRegistered = async (subscriptionId: string): Promise<boolean> => {
|
export const isCopilotFeatureRegistered = async (subscriptionId: string): Promise<boolean> => {
|
||||||
const api_version = "2021-07-01";
|
const api_version = "2021-07-01";
|
||||||
const url = `${configContext.ARM_ENDPOINT}/subscriptions/${subscriptionId}/providers/Microsoft.Features/featureProviders/Microsoft.DocumentDB/subscriptionFeatureRegistrations/MicrosoftCopilotForAzureInCDB?api-version=${api_version}`;
|
const url = `${configContext.ARM_ENDPOINT}/subscriptions/${subscriptionId}/providers/Microsoft.Features/featureProviders/Microsoft.DocumentDB/subscriptionFeatureRegistrations/MicrosoftCopilotForAzureInCDB?api-version=${api_version}`;
|
||||||
@ -44,9 +63,7 @@ export const isCopilotFeatureRegistered = async (subscriptionId: string): Promis
|
|||||||
let response;
|
let response;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await window.fetch(url, {
|
response = await fetchWithTimeout(url, headers);
|
||||||
headers,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -67,9 +84,7 @@ export const getCopilotEnabled = async (): Promise<boolean> => {
|
|||||||
let response;
|
let response;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await window.fetch(url, {
|
response = await fetchWithTimeout(url, headers);
|
||||||
headers,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user