mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
Retry with first fetcher to avoid fallback on resume
This commit is contained in:
@@ -97,6 +97,13 @@ export function createFetch(): Fetch {
|
||||
}
|
||||
const json = JSON.parse(text); // Verify JSON
|
||||
options.logger.info(`fetching: ${fetcher.name} succeeded (JSON)`);
|
||||
if (fetcher !== _fetchers[0]) {
|
||||
const retry = await retryFetch(_fetchers[0], url, options);
|
||||
if ('res' in retry && retry.res.ok) {
|
||||
_fetcher = _fetchers[0];
|
||||
return retry.res;
|
||||
}
|
||||
}
|
||||
_fetcher = fetcher;
|
||||
return new FetchResponseImpl(
|
||||
res.status,
|
||||
@@ -122,6 +129,35 @@ export function createFetch(): Fetch {
|
||||
};
|
||||
}
|
||||
|
||||
async function retryFetch(fetcher: Fetcher, url: string, options: FetchOptions): Promise<{ res: FetchResponse } | { err: any }> {
|
||||
try {
|
||||
const res = await fetcher.fetch(url, options);
|
||||
if (!res.ok) {
|
||||
options.logger.info(`fetching: ${fetcher.name} failed with status: ${res.status} ${res.statusText}`);
|
||||
return { res };
|
||||
}
|
||||
if (!options.expectJSON) {
|
||||
options.logger.info(`fetching: ${fetcher.name} succeeded (not JSON)`);
|
||||
return { res };
|
||||
}
|
||||
const text = await res.text();
|
||||
const json = JSON.parse(text); // Verify JSON
|
||||
options.logger.info(`fetching: ${fetcher.name} succeeded (JSON)`);
|
||||
return {
|
||||
res: new FetchResponseImpl(
|
||||
res.status,
|
||||
res.statusText,
|
||||
res.headers,
|
||||
async () => text,
|
||||
async () => json,
|
||||
)
|
||||
};
|
||||
} catch (err) {
|
||||
options.logger.info(`fetching: ${fetcher.name} failed with error: ${err.message}`);
|
||||
return { err };
|
||||
}
|
||||
}
|
||||
|
||||
export const fetching = createFetch();
|
||||
|
||||
class FetchResponseImpl implements FetchResponse {
|
||||
|
||||
Reference in New Issue
Block a user