Skip to content

Commit

Permalink
check response code before saving body
Browse files Browse the repository at this point in the history
  • Loading branch information
Lance Liu committed Jul 24, 2020
1 parent efd847e commit 96fb031
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugins/admin/pkg/command/profiling/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -161,10 +162,17 @@ func (d *Downloader) Download(t ProfileType, output io.Writer, options ...Downlo
}
}
resp, err := d.client.Do(req)
defer resp.Body.Close()
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return fmt.Errorf("download error: %s, code %d", string(body), resp.StatusCode)
}
_, err = io.Copy(output, resp.Body)
if err != nil {
return err
Expand Down

0 comments on commit 96fb031

Please sign in to comment.