mirror of
https://github.com/safing/portbase
synced 2025-09-01 01:59:48 +00:00
Do not ingore HTTP status code when fetching files
This commit is contained in:
parent
3d9920935e
commit
8a18810c66
1 changed files with 8 additions and 0 deletions
|
@ -50,6 +50,10 @@ func (reg *ResourceRegistry) fetchFile(rv *ResourceVersion, tries int) error {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("error fetching url (%s): %s", downloadURL, resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
// download and write file
|
// download and write file
|
||||||
n, err := io.Copy(atomicFile, resp.Body)
|
n, err := io.Copy(atomicFile, resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,6 +100,10 @@ func (reg *ResourceRegistry) fetchData(downloadPath string, tries int) ([]byte,
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("error fetching url (%s): %s", downloadURL, resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
// download and write file
|
// download and write file
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, resp.ContentLength))
|
buf := bytes.NewBuffer(make([]byte, 0, resp.ContentLength))
|
||||||
n, err := io.Copy(buf, resp.Body)
|
n, err := io.Copy(buf, resp.Body)
|
||||||
|
|
Loading…
Add table
Reference in a new issue