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;
|
||||
|
||||
export default async (url: string, options = {}) => {
|
||||
if (!global.AbortController) {
|
||||
return nodeFetch(url, options);
|
||||
}
|
||||
try {
|
||||
if (!global.AbortController) {
|
||||
return nodeFetch(url, options);
|
||||
}
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => {
|
||||
controller.abort();
|
||||
}, TIMEOUT);
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => {
|
||||
controller.abort();
|
||||
}, TIMEOUT);
|
||||
const res = await nodeFetch(url, { signal: controller.signal, ...options });
|
||||
clearTimeout(timeout);
|
||||
return res;
|
||||
const res = await nodeFetch(url, { signal: controller.signal, ...options });
|
||||
clearTimeout(timeout);
|
||||
return res;
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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) => {
|
||||
const lastCheckFile = join(tmpdir(), VERSION_CACHE_FILE);
|
||||
writeFileSync(lastCheckFile, version);
|
||||
if (version) {
|
||||
const lastCheckFile = join(tmpdir(), VERSION_CACHE_FILE);
|
||||
writeFileSync(lastCheckFile, version);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user