Skip to content

Commit 37717d6

Browse files
authored
fix(core): Could not fetch endpoints (#6418)
## Problem While starting the release process we found an problem where the endpoints couldn't be fetched because the resourceFetcher was expecting a string but the httpResourceFetcher was returning a Resource ## Solution If its a string then return the contents from the resource fetcher directly, otherwise consider it as a response and get the text from the request --- - 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 f004173 commit 37717d6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/core/src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ export function registerGenericCommands(extensionContext: vscode.ExtensionContex
190190
* https://docs.aws.amazon.com/general/latest/gr/rande.html
191191
*/
192192
export function makeEndpointsProvider() {
193-
let localManifestFetcher: ResourceFetcher
194-
let remoteManifestFetcher: ResourceFetcher
193+
let localManifestFetcher: ResourceFetcher<string>
194+
let remoteManifestFetcher: ResourceFetcher<Response>
195195
if (isWeb()) {
196196
localManifestFetcher = { get: async () => JSON.stringify(endpoints) }
197197
// Cannot use HttpResourceFetcher due to web mode breaking on import
198-
remoteManifestFetcher = { get: async () => (await fetch(endpointsFileUrl)).text() }
198+
remoteManifestFetcher = { get: async () => await fetch(endpointsFileUrl) }
199199
} else {
200200
localManifestFetcher = new FileResourceFetcher(globals.manifestPaths.endpoints)
201201
// HACK: HttpResourceFetcher breaks web mode when imported, so we use webpack.IgnorePlugin()

packages/core/src/shared/regions/regionProvider.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ export class RegionProvider {
196196
}
197197
}
198198

199-
export async function getEndpointsFromFetcher(fetcher: ResourceFetcher): Promise<Endpoints> {
200-
const endpointsJson = await fetcher.get()
199+
export async function getEndpointsFromFetcher(
200+
fetcher: ResourceFetcher<string> | ResourceFetcher<Response>
201+
): Promise<Endpoints> {
202+
const contents = await fetcher.get()
203+
const endpointsJson = typeof contents === 'string' ? contents : await contents?.text()
201204
if (!endpointsJson) {
202205
throw new Error('Failed to get resource')
203206
}

0 commit comments

Comments
 (0)