fix: handle aborted request in docker and remove redundant call (#1161)

This commit is contained in:
Ihor Karpiuk
2023-07-07 18:15:06 +03:00
committed by GitHub
parent dcf4c0fd4f
commit ac9a494c92
3 changed files with 21 additions and 14 deletions

View File

@@ -3,15 +3,19 @@ import nodeFetch from 'node-fetch';
const TIMEOUT = 3000;
export default async (url: string, options = {}) => {
try {
if (!global.AbortController) {
return nodeFetch(url, options);
}
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();
}, TIMEOUT);
const res = await nodeFetch(url, { signal: controller.signal, ...options });
clearTimeout(timeout);
return res;
} catch (e) {
return;
}
};

View File

@@ -32,9 +32,10 @@ export const notifyUpdateCliVersion = () => {
const isNewVersionAvailable = (current: string, latest: string) => compare(current, latest) < 0;
const getLatestVersion = async (packageName: string): Promise<string> => {
const getLatestVersion = async (packageName: string): Promise<string | undefined> => {
const latestUrl = `http://registry.npmjs.org/${packageName}/latest`;
const response = await fetch(latestUrl);
if (!response) return;
const info = await response.json();
return info.version;
};
@@ -46,8 +47,10 @@ export const cacheLatestVersion = () => {
getLatestVersion(name)
.then((version) => {
if (version) {
const lastCheckFile = join(tmpdir(), VERSION_CACHE_FILE);
writeFileSync(lastCheckFile, version);
}
})
.catch(() => {});
};

View File

@@ -496,7 +496,7 @@ export async function sendTelemetry(
} = argv;
const event_time = new Date().toISOString();
const redoclyClient = new RedoclyClient();
const logged_in = await redoclyClient.isAuthorizedWithRedoclyByRegion();
const logged_in = redoclyClient.hasTokens();
const data: Analytics = {
event: 'cli_command',
event_time,