Skip to content

Commit c767cee

Browse files
authored
refactor(core): Allow retries while fetching etags (aws#6402)
## Problem We currently only retry normal get requests in the httpResourceFetcher ## Solution Retry etag get requests as well --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2a20e3c commit c767cee

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

packages/core/src/shared/resourcefetcher/httpResourceFetcher.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ export class HttpResourceFetcher implements ResourceFetcher<Response> {
3939
*/
4040
public get(): Promise<Response | undefined> {
4141
this.logger.verbose(`downloading: ${this.logText()}`)
42-
return withRetries(() => this.downloadRequest(), {
43-
maxRetries: this.params.retries ?? 1,
44-
})
42+
return this.downloadRequest()
4543
}
4644

4745
/**
@@ -99,16 +97,23 @@ export class HttpResourceFetcher implements ResourceFetcher<Response> {
9997
}
10098

10199
private async getResponseFromGetRequest(timeout?: Timeout, headers?: RequestHeaders): Promise<Response> {
102-
const req = request.fetch('GET', this.url, {
103-
headers: this.buildRequestHeaders(headers),
104-
})
105-
106-
const cancelListener = timeout?.token.onCancellationRequested((event) => {
107-
this.logCancellation(event)
108-
req.cancel()
109-
})
110-
111-
return req.response.finally(() => cancelListener?.dispose())
100+
return withRetries(
101+
() => {
102+
const req = request.fetch('GET', this.url, {
103+
headers: this.buildRequestHeaders(headers),
104+
})
105+
106+
const cancelListener = timeout?.token.onCancellationRequested((event) => {
107+
this.logCancellation(event)
108+
req.cancel()
109+
})
110+
111+
return req.response.finally(() => cancelListener?.dispose())
112+
},
113+
{
114+
maxRetries: this.params.retries ?? 1,
115+
}
116+
)
112117
}
113118

114119
private buildRequestHeaders(requestHeaders?: RequestHeaders): Headers {

0 commit comments

Comments
 (0)