Skip to content

Commit

Permalink
check http response when downloading file.
Browse files Browse the repository at this point in the history
  • Loading branch information
preslavgerchev committed Sep 25, 2023
1 parent 7aff459 commit c854698
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,17 @@ func installVersion(name string, version string) (*Provider, error) {
log.Debug().Str("url", url).Msg("installing provider from URL")
res, err := http.Get(url)
if err != nil {
log.Debug().Str("url", url).Msg("failed to install form URL (get request)")
log.Debug().Str("url", url).Msg("failed to install from URL (get request)")
return nil, errors.Wrap(err, "failed to install "+name+"-"+version)
}
if res.StatusCode == http.StatusNotFound {
return nil, errors.New("cannot find provider " + name + "-" + version + " under url " + url)
} else if res.StatusCode != http.StatusOK {
log.Debug().Str("url", url).Int("status", res.StatusCode).Msg("failed to install from URL (status code)")
return nil, errors.New("failed to install " + name + "-" + version + ", received status code: " + res.Status)
}

// else we know we got a 200 response, we can safely install
installed, err := InstallIO(res.Body, InstallConf{
Dst: DefaultPath,
})
Expand Down

0 comments on commit c854698

Please sign in to comment.