Always close response body in uploads

This commit is contained in:
Tulir Asokan 2023-07-19 14:19:04 +03:00
parent a4639eb668
commit bf277e197f

View file

@ -154,14 +154,13 @@ func (c *Client) FinalizeUploadMedia(upload *StartGoogleUpload) (*MediaUpload, e
if resErr != nil {
panic(resErr)
}
defer res.Body.Close()
statusCode := res.StatusCode
if statusCode != 200 {
return nil, errFinalizeUploadMedia
}
defer res.Body.Close()
rHeaders := res.Header
googleResponse, err3 := io.ReadAll(base64.NewDecoder(base64.StdEncoding, res.Body))
if err3 != nil {
@ -202,6 +201,7 @@ func (c *Client) StartUploadMedia(encryptedImageBytes []byte, mime string) (*Sta
if resErr != nil {
panic(resErr)
}
defer res.Body.Close()
statusCode := res.StatusCode
if statusCode != 200 {