mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-02-21 11:47:14 +00: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 * 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> => {
|
||||
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}`;
|
||||
@ -44,9 +63,7 @@ export const isCopilotFeatureRegistered = async (subscriptionId: string): Promis
|
||||
let response;
|
||||
|
||||
try {
|
||||
response = await window.fetch(url, {
|
||||
headers,
|
||||
});
|
||||
response = await fetchWithTimeout(url, headers);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
@ -67,9 +84,7 @@ export const getCopilotEnabled = async (): Promise<boolean> => {
|
||||
let response;
|
||||
|
||||
try {
|
||||
response = await window.fetch(url, {
|
||||
headers,
|
||||
});
|
||||
response = await fetchWithTimeout(url, headers);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user