@@ -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}
162166exports . removeCluster = removeCluster ;
163167async 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}
179181exports . 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 ( ) ) ;
0 commit comments