add should fail on 40x

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
Yoan Blanc 2020-06-20 09:49:11 +02:00
parent 82f5ec9612
commit ca23ae441e
No known key found for this signature in database
GPG Key ID: 6058CF4574298812
2 changed files with 9 additions and 0 deletions

View File

@ -0,0 +1,4 @@
FROM debian:9.11
# Testing that any HTTP failure is handled properly
ADD https://httpstat.us/404 .

View File

@ -545,6 +545,11 @@ func DownloadFileToDest(rawurl, dest string, uid, gid int64) error {
return err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return fmt.Errorf("%s failed with %d", rawurl, resp.StatusCode)
}
if err := CreateFile(dest, resp.Body, 0600, uint32(uid), uint32(gid)); err != nil {
return err
}