mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 12:47:48 +00:00
fix: handle aborted request in docker and remove redundant call (#1161)
This commit is contained in:
@@ -3,15 +3,19 @@ import nodeFetch from 'node-fetch';
|
|||||||
const TIMEOUT = 3000;
|
const TIMEOUT = 3000;
|
||||||
|
|
||||||
export default async (url: string, options = {}) => {
|
export default async (url: string, options = {}) => {
|
||||||
if (!global.AbortController) {
|
try {
|
||||||
return nodeFetch(url, options);
|
if (!global.AbortController) {
|
||||||
}
|
return nodeFetch(url, options);
|
||||||
|
}
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
controller.abort();
|
||||||
|
}, TIMEOUT);
|
||||||
|
|
||||||
const controller = new AbortController();
|
const res = await nodeFetch(url, { signal: controller.signal, ...options });
|
||||||
const timeout = setTimeout(() => {
|
clearTimeout(timeout);
|
||||||
controller.abort();
|
return res;
|
||||||
}, TIMEOUT);
|
} catch (e) {
|
||||||
const res = await nodeFetch(url, { signal: controller.signal, ...options });
|
return;
|
||||||
clearTimeout(timeout);
|
}
|
||||||
return res;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,9 +32,10 @@ export const notifyUpdateCliVersion = () => {
|
|||||||
|
|
||||||
const isNewVersionAvailable = (current: string, latest: string) => compare(current, latest) < 0;
|
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 latestUrl = `http://registry.npmjs.org/${packageName}/latest`;
|
||||||
const response = await fetch(latestUrl);
|
const response = await fetch(latestUrl);
|
||||||
|
if (!response) return;
|
||||||
const info = await response.json();
|
const info = await response.json();
|
||||||
return info.version;
|
return info.version;
|
||||||
};
|
};
|
||||||
@@ -46,8 +47,10 @@ export const cacheLatestVersion = () => {
|
|||||||
|
|
||||||
getLatestVersion(name)
|
getLatestVersion(name)
|
||||||
.then((version) => {
|
.then((version) => {
|
||||||
const lastCheckFile = join(tmpdir(), VERSION_CACHE_FILE);
|
if (version) {
|
||||||
writeFileSync(lastCheckFile, version);
|
const lastCheckFile = join(tmpdir(), VERSION_CACHE_FILE);
|
||||||
|
writeFileSync(lastCheckFile, version);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ export async function sendTelemetry(
|
|||||||
} = argv;
|
} = argv;
|
||||||
const event_time = new Date().toISOString();
|
const event_time = new Date().toISOString();
|
||||||
const redoclyClient = new RedoclyClient();
|
const redoclyClient = new RedoclyClient();
|
||||||
const logged_in = await redoclyClient.isAuthorizedWithRedoclyByRegion();
|
const logged_in = redoclyClient.hasTokens();
|
||||||
const data: Analytics = {
|
const data: Analytics = {
|
||||||
event: 'cli_command',
|
event: 'cli_command',
|
||||||
event_time,
|
event_time,
|
||||||
|
|||||||
Reference in New Issue
Block a user