Add check of HTTP status when downloading
This commit is contained in:
parent
98eb833dc0
commit
e5b4639cab
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user