@@ -195,19 +195,24 @@ func (e *Service) GetRebalanceRecommendationEvent() (rebalanceRec *RebalanceReco
195195
196196// GetMetadataInfo generic function for retrieving ec2 metadata
197197func (e * Service ) GetMetadataInfo (path string ) (info string , err error ) {
198+ metadataInfo := ""
198199 resp , err := e .Request (path )
199- if resp != nil && (resp .StatusCode < 200 || resp .StatusCode >= 300 ) {
200- return "" , fmt .Errorf ("Metadata request received http status code: %d" , resp .StatusCode )
201- }
202200 if err != nil {
203201 return "" , fmt .Errorf ("Unable to parse metadata response: %w" , err )
204202 }
205- defer resp .Body .Close ()
206- body , err := ioutil .ReadAll (resp .Body )
207- if err != nil {
208- return "" , fmt .Errorf ("Unable to parse http response: %w" , err )
203+ if resp != nil {
204+ defer resp .Body .Close ()
205+ body , err := ioutil .ReadAll (resp .Body )
206+ if err != nil {
207+ return "" , fmt .Errorf ("Unable to parse http response. Status code: %d. %w" , resp .StatusCode , err )
208+ }
209+ metadataInfo = string (body )
210+ if resp .StatusCode < 200 || resp .StatusCode >= 300 {
211+ log .Info ().Msgf ("Metadata response status code: %d. Body: %s" , resp .StatusCode , metadataInfo )
212+ return "" , fmt .Errorf ("Metadata request received http status code: %d" , resp .StatusCode )
213+ }
209214 }
210- return string ( body ) , nil
215+ return metadataInfo , nil
211216}
212217
213218// Request sends an http request to IMDSv1 or v2 at the specified path
0 commit comments