Add check of HTTP status when downloading

This commit is contained in:
Lucas BEE 2020-04-07 17:45:39 +02:00
parent 98eb833dc0
commit e5b4639cab
2 changed files with 10 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"net/http"
"strconv"
@ -34,6 +35,10 @@ func Refresh(env *web.Env) error {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("got HTTP error %s", resp.Status)
}
// Read all the file (~5MB) in memory
// We do that because the ~1 000 000 upserts take too long, and the IMDB
// server will cut our connection after ~2h

View File

@ -1,6 +1,7 @@
package web
import (
"fmt"
"image"
"image/jpeg"
"net/http"
@ -26,6 +27,10 @@ var Download = func(srcURL, dest string, scale bool) error {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("got HTTP error %s", resp.Status)
}
image, _, err := image.Decode(resp.Body)
if err != nil {
return err