Skip to content

Commit 886c833

Browse files
authored
fix: requests hang, discard response body (#47)
* fix: requests hang, discard response body * f * dist
1 parent 5fedf27 commit 886c833

File tree

12 files changed

+67
-22
lines changed

12 files changed

+67
-22
lines changed

dist/applications.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ async function getApplicationDetails(vendorPortalApi, appSlug) {
1111
const listAppsUri = `${vendorPortalApi.endpoint}/apps`;
1212
const listAppsRes = await http.get(listAppsUri);
1313
if (listAppsRes.message.statusCode != 200) {
14+
// discard the response body
15+
await listAppsRes.readBody();
1416
throw new Error(`Failed to list apps: Server responded with ${listAppsRes.message.statusCode}`);
1517
}
1618
const listAppsBody = JSON.parse(await listAppsRes.readBody());

dist/channels.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ async function createChannel(vendorPortalApi, appSlug, channelName) {
2121
const createChannelUri = `${vendorPortalApi.endpoint}/app/${app.id}/channel`;
2222
const createChannelRes = await http.post(createChannelUri, JSON.stringify(reqBody));
2323
if (createChannelRes.message.statusCode != 201) {
24+
// discard the response body
25+
await createChannelRes.readBody();
2426
throw new Error(`Failed to create channel: Server responded with ${createChannelRes.message.statusCode}`);
2527
}
2628
const createChannelBody = JSON.parse(await createChannelRes.readBody());
@@ -45,6 +47,8 @@ async function getChannelByApplicationId(vendorPortalApi, appid, { slug, name })
4547
const listChannelsUri = `${vendorPortalApi.endpoint}/app/${appid}/channels?excludeDetail=true`;
4648
const listChannelsRes = await http.get(listChannelsUri);
4749
if (listChannelsRes.message.statusCode != 200) {
50+
// discard the response body
51+
await listChannelsRes.readBody();
4852
throw new Error(`Failed to list channels: Server responded with ${listChannelsRes.message.statusCode}`);
4953
}
5054
const listChannelsBody = JSON.parse(await listChannelsRes.readBody());
@@ -62,6 +66,8 @@ async function archiveChannel(vendorPortalApi, appSlug, channelSlug) {
6266
const archiveChannelUri = `${vendorPortalApi.endpoint}/app/${app.id}/channel/${channel.id}`;
6367
const archiveChannelRes = await http.del(archiveChannelUri);
6468
if (archiveChannelRes.message.statusCode != 200) {
69+
// discard the response body
70+
await archiveChannelRes.readBody();
6571
throw new Error(`Failed to archive channel: Server responded with ${archiveChannelRes.message.statusCode}`);
6672
}
6773
// discard the response body

dist/clusters.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ async function getClusterDetails(vendorPortalApi, clusterId) {
129129
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}`;
130130
const res = await http.get(uri);
131131
if (res.message.statusCode != 200) {
132+
// discard the response body
133+
await res.readBody();
132134
throw new StatusError(`Failed to get cluster: Server responded with ${res.message.statusCode}`, res.message.statusCode);
133135
}
134136
const body = JSON.parse(await res.readBody());
@@ -143,6 +145,8 @@ async function getKubeconfig(vendorPortalApi, clusterId) {
143145
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}/kubeconfig`;
144146
const res = await http.get(uri);
145147
if (res.message.statusCode != 200) {
148+
// discard the response body
149+
await res.readBody();
146150
throw new StatusError(`Failed to get kubeconfig: Server responded with ${res.message.statusCode}`, res.message.statusCode);
147151
}
148152
const body = JSON.parse(await res.readBody());
@@ -153,11 +157,11 @@ async function removeCluster(vendorPortalApi, clusterId) {
153157
const http = await vendorPortalApi.client();
154158
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}`;
155159
const res = await http.del(uri);
160+
// discard the response body
161+
await res.readBody();
156162
if (res.message.statusCode != 200) {
157163
throw new StatusError(`Failed to remove cluster: Server responded with ${res.message.statusCode}`, res.message.statusCode);
158164
}
159-
// discard the response body
160-
await res.readBody();
161165
}
162166
exports.removeCluster = removeCluster;
163167
async function upgradeCluster(vendorPortalApi, clusterId, k8sVersion) {
@@ -167,13 +171,11 @@ async function upgradeCluster(vendorPortalApi, clusterId, k8sVersion) {
167171
};
168172
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}/upgrade`;
169173
const res = await http.post(uri, JSON.stringify(reqBody));
174+
// discard the response body
175+
await res.readBody();
170176
if (res.message.statusCode != 200) {
171177
throw new StatusError(`Failed to upgrade cluster: Server responded with ${res.message.statusCode}`, res.message.statusCode);
172178
}
173-
else {
174-
// discard the response body
175-
await res.readBody();
176-
}
177179
return getClusterDetails(vendorPortalApi, clusterId);
178180
}
179181
exports.upgradeCluster = upgradeCluster;
@@ -182,6 +184,8 @@ async function getClusterVersions(vendorPortalApi) {
182184
const uri = `${vendorPortalApi.endpoint}/cluster/versions`;
183185
const res = await http.get(uri);
184186
if (res.message.statusCode != 200) {
187+
// discard the response body
188+
await res.readBody();
185189
throw new StatusError(`Failed to get cluster versions: Server responded with ${res.message.statusCode}`, res.message.statusCode);
186190
}
187191
const body = JSON.parse(await res.readBody());
@@ -310,6 +314,8 @@ async function getAddonDetails(vendorPortalApi, clusterId, addonId) {
310314
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}/addons`;
311315
const res = await http.get(uri);
312316
if (res.message.statusCode != 200) {
317+
// discard the response body
318+
await res.readBody();
313319
throw new StatusError(`Failed to get add-on: Server responded with ${res.message.statusCode}`, res.message.statusCode);
314320
}
315321
const body = JSON.parse(await res.readBody());

dist/customers.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ async function createCustomer(vendorPortalApi, appSlug, name, email, licenseType
5757
const downloadLicenseRes = await http.get(downloadLicenseUri);
5858
// If response is 403, ignore as we could be using a trial license (on builders plan)
5959
if (downloadLicenseRes.message.statusCode != 200 && downloadLicenseRes.message.statusCode != 403) {
60+
// discard the response body
61+
await downloadLicenseRes.readBody();
6062
throw new Error(`Failed to download created license: Server responded with ${downloadLicenseRes.message.statusCode}`);
6163
}
6264
let downloadLicenseBody = "";
@@ -81,11 +83,11 @@ async function archiveCustomer(vendorPortalApi, customerId) {
8183
console.log(`Archive Customer ...`);
8284
const archiveCustomerUri = `${vendorPortalApi.endpoint}/customer/${customerId}/archive`;
8385
const archiveCustomerRes = await http.post(archiveCustomerUri, undefined);
86+
// discard the response body
87+
await archiveCustomerRes.readBody();
8488
if (archiveCustomerRes.message.statusCode != 204) {
8589
throw new Error(`Failed to archive customer: Server responded with ${archiveCustomerRes.message.statusCode}`);
8690
}
87-
// discard the response body
88-
await archiveCustomerRes.readBody();
8991
}
9092
exports.archiveCustomer = archiveCustomer;
9193
async function getUsedKubernetesDistributions(vendorPortalApi, appSlug) {
@@ -96,6 +98,8 @@ async function getUsedKubernetesDistributions(vendorPortalApi, appSlug) {
9698
const getClusterUsageUri = `${vendorPortalApi.endpoint}/app/${app.id}/cluster-usage`;
9799
const getClusterUsageRes = await http.get(getClusterUsageUri);
98100
if (getClusterUsageRes.message.statusCode != 200) {
101+
// discard the response body
102+
await getClusterUsageRes.readBody();
99103
throw new Error(`Failed to get Cluster Usage: Server responded with ${getClusterUsageRes.message.statusCode}`);
100104
}
101105
const getClusterUsageBody = JSON.parse(await getClusterUsageRes.readBody());

dist/releases.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ async function createRelease(vendorPortalApi, appSlug, yamlDir) {
2929
const createReleaseUri = `${vendorPortalApi.endpoint}/app/${app.id}/release`;
3030
const createReleaseRes = await http.post(createReleaseUri, JSON.stringify(reqBody));
3131
if (createReleaseRes.message.statusCode != 201) {
32+
// discard the response body
33+
await createReleaseRes.readBody();
3234
throw new Error(`Failed to create release: Server responded with ${createReleaseRes.message.statusCode}`);
3335
}
3436
const createReleaseBody = JSON.parse(await createReleaseRes.readBody());
@@ -57,6 +59,8 @@ async function createReleaseFromChart(vendorPortalApi, appSlug, chart) {
5759
const createReleaseUri = `${vendorPortalApi.endpoint}/app/${app.id}/release`;
5860
const createReleaseRes = await http.post(createReleaseUri, JSON.stringify(reqBody));
5961
if (createReleaseRes.message.statusCode != 201) {
62+
// discard the response body
63+
await createReleaseRes.readBody();
6064
throw new Error(`Failed to create release: Server responded with ${createReleaseRes.message.statusCode}`);
6165
}
6266
const createReleaseBody = JSON.parse(await createReleaseRes.readBody());
@@ -174,7 +178,6 @@ async function promoteReleaseByAppId(vendorPortalApi, appId, channelId, releaseS
174178
const uri = `${vendorPortalApi.endpoint}/app/${appId}/release/${releaseSequence}/promote`;
175179
const res = await http.post(uri, JSON.stringify(reqBody));
176180
if (res.message.statusCode != 200) {
177-
// If res has a body, read it and add it to the error message
178181
let body = "";
179182
try {
180183
body = await res.readBody();
@@ -232,6 +235,8 @@ async function getReleaseByAppId(vendorPortalApi, appId, releaseSequence) {
232235
const uri = `${vendorPortalApi.endpoint}/app/${appId}/release/${releaseSequence}`;
233236
const res = await http.get(uri);
234237
if (res.message.statusCode != 200) {
238+
// discard the response body
239+
await res.readBody();
235240
throw new Error(`Failed to get release: Server responded with ${res.message.statusCode}`);
236241
}
237242
const body = JSON.parse(await res.readBody());
@@ -263,7 +268,6 @@ async function reportCompatibilityResultByAppId(vendorPortalApi, appId, releaseS
263268
const uri = `${vendorPortalApi.endpoint}/app/${appId}/release/${releaseSequence}/compatibility`;
264269
const res = await http.post(uri, JSON.stringify(reqBody));
265270
if (res.message.statusCode != 201) {
266-
// If res has a body, read it and add it to the error message
267271
let body = "";
268272
try {
269273
body = await res.readBody();

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "replicated-lib",
3-
"version": "0.0.1-beta.16",
3+
"version": "0.0.1-beta.17",
44
"description": "Can interact with the vendor portal api!",
55
"scripts": {
66
"build": "rm -rf dist && tsc --build",

src/applications.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export async function getApplicationDetails(vendorPortalApi: VendorPortalApi, ap
1414
const listAppsUri = `${vendorPortalApi.endpoint}/apps`;
1515
const listAppsRes = await http.get(listAppsUri);
1616
if (listAppsRes.message.statusCode != 200) {
17+
// discard the response body
18+
await listAppsRes.readBody();
1719
throw new Error(`Failed to list apps: Server responded with ${listAppsRes.message.statusCode}`);
1820
}
1921
const listAppsBody: any = JSON.parse(await listAppsRes.readBody());

src/channels.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export async function createChannel(vendorPortalApi: VendorPortalApi, appSlug: s
2727
const createChannelUri = `${vendorPortalApi.endpoint}/app/${app.id}/channel`;
2828
const createChannelRes = await http.post(createChannelUri, JSON.stringify(reqBody));
2929
if (createChannelRes.message.statusCode != 201) {
30+
// discard the response body
31+
await createChannelRes.readBody();
3032
throw new Error(`Failed to create channel: Server responded with ${createChannelRes.message.statusCode}`);
3133
}
3234
const createChannelBody: any = JSON.parse(await createChannelRes.readBody());
@@ -60,6 +62,8 @@ async function getChannelByApplicationId(vendorPortalApi: VendorPortalApi, appid
6062
const listChannelsUri = `${vendorPortalApi.endpoint}/app/${appid}/channels?excludeDetail=true`;
6163
const listChannelsRes = await http.get(listChannelsUri);
6264
if (listChannelsRes.message.statusCode != 200) {
65+
// discard the response body
66+
await listChannelsRes.readBody();
6367
throw new Error(`Failed to list channels: Server responded with ${listChannelsRes.message.statusCode}`);
6468
}
6569
const listChannelsBody: any = JSON.parse(await listChannelsRes.readBody());
@@ -83,6 +87,8 @@ export async function archiveChannel(vendorPortalApi: VendorPortalApi, appSlug:
8387
const archiveChannelUri = `${vendorPortalApi.endpoint}/app/${app.id}/channel/${channel.id}`;
8488
const archiveChannelRes = await http.del(archiveChannelUri);
8589
if (archiveChannelRes.message.statusCode != 200) {
90+
// discard the response body
91+
await archiveChannelRes.readBody();
8692
throw new Error(`Failed to archive channel: Server responded with ${archiveChannelRes.message.statusCode}`);
8793
}
8894
// discard the response body

src/clusters.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ async function getClusterDetails(vendorPortalApi: VendorPortalApi, clusterId: st
204204
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}`;
205205
const res = await http.get(uri);
206206
if (res.message.statusCode != 200) {
207+
// discard the response body
208+
await res.readBody();
207209
throw new StatusError(`Failed to get cluster: Server responded with ${res.message.statusCode}`, res.message.statusCode);
208210
}
209211

@@ -222,6 +224,8 @@ export async function getKubeconfig(vendorPortalApi: VendorPortalApi, clusterId:
222224
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}/kubeconfig`;
223225
const res = await http.get(uri);
224226
if (res.message.statusCode != 200) {
227+
// discard the response body
228+
await res.readBody();
225229
throw new StatusError(`Failed to get kubeconfig: Server responded with ${res.message.statusCode}`, res.message.statusCode);
226230
}
227231

@@ -235,11 +239,11 @@ export async function removeCluster(vendorPortalApi: VendorPortalApi, clusterId:
235239

236240
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}`;
237241
const res = await http.del(uri);
242+
// discard the response body
243+
await res.readBody();
238244
if (res.message.statusCode != 200) {
239245
throw new StatusError(`Failed to remove cluster: Server responded with ${res.message.statusCode}`, res.message.statusCode);
240246
}
241-
// discard the response body
242-
await res.readBody();
243247
}
244248

245249
export async function upgradeCluster(vendorPortalApi: VendorPortalApi, clusterId: string, k8sVersion: string): Promise<Cluster> {
@@ -251,11 +255,10 @@ export async function upgradeCluster(vendorPortalApi: VendorPortalApi, clusterId
251255

252256
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}/upgrade`;
253257
const res = await http.post(uri, JSON.stringify(reqBody));
258+
// discard the response body
259+
await res.readBody();
254260
if (res.message.statusCode != 200) {
255261
throw new StatusError(`Failed to upgrade cluster: Server responded with ${res.message.statusCode}`, res.message.statusCode);
256-
} else {
257-
// discard the response body
258-
await res.readBody();
259262
}
260263

261264
return getClusterDetails(vendorPortalApi, clusterId);
@@ -266,6 +269,8 @@ export async function getClusterVersions(vendorPortalApi: VendorPortalApi): Prom
266269
const uri = `${vendorPortalApi.endpoint}/cluster/versions`;
267270
const res = await http.get(uri);
268271
if (res.message.statusCode != 200) {
272+
// discard the response body
273+
await res.readBody();
269274
throw new StatusError(`Failed to get cluster versions: Server responded with ${res.message.statusCode}`, res.message.statusCode);
270275
}
271276

@@ -408,6 +413,8 @@ async function getAddonDetails(vendorPortalApi: VendorPortalApi, clusterId: stri
408413
const uri = `${vendorPortalApi.endpoint}/cluster/${clusterId}/addons`;
409414
const res = await http.get(uri);
410415
if (res.message.statusCode != 200) {
416+
// discard the response body
417+
await res.readBody();
411418
throw new StatusError(`Failed to get add-on: Server responded with ${res.message.statusCode}`, res.message.statusCode);
412419
}
413420

0 commit comments

Comments
 (0)