-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds retry to the fetch requests. It also fixes the tests that were having issues when running locally.
- Loading branch information
Showing
11 changed files
with
62 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Uri, Webview } from "vscode"; | ||
import { Errors, ExtensionError } from "./error"; | ||
|
||
export function getNonce() { | ||
let text = ""; | ||
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
for (let i = 0; i < 32; i++) { | ||
text += possible.charAt(Math.floor(Math.random() * possible.length)); | ||
} | ||
return text; | ||
} | ||
|
||
export function getUri(webview: Webview, extensionUri: Uri, pathList: string[]) { | ||
return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList)); | ||
} | ||
|
||
export async function fetchWithRetry( | ||
url: string, | ||
init?: RequestInit, | ||
timeout = 60000, | ||
interval = 5000 | ||
): Promise<Response> { | ||
const startTime = Date.now(); | ||
|
||
async function attemptFetch(): Promise<Response> { | ||
try { | ||
const response = await fetch(url, init); | ||
return response; | ||
} catch (error) { | ||
console.error("[Fetch]", "Error fetching: ", error); | ||
if (Date.now() - startTime < timeout) { | ||
await new Promise(resolve => setTimeout(resolve, interval)); | ||
return attemptFetch(); | ||
} else { | ||
throw new ExtensionError(Errors.fetchTimeoutError, `Failed to fetch after ${timeout}ms: ${error}`); | ||
} | ||
} | ||
} | ||
|
||
return attemptFetch(); | ||
} |