Add check of HTTP status when downloading
This commit is contained in:
parent
98eb833dc0
commit
e5b4639cab
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -34,6 +35,10 @@ func Refresh(env *web.Env) error {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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
|
// Read all the file (~5MB) in memory
|
||||||
// We do that because the ~1 000 000 upserts take too long, and the IMDB
|
// We do that because the ~1 000 000 upserts take too long, and the IMDB
|
||||||
// server will cut our connection after ~2h
|
// server will cut our connection after ~2h
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -26,6 +27,10 @@ var Download = func(srcURL, dest string, scale bool) error {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("got HTTP error %s", resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
image, _, err := image.Decode(resp.Body)
|
image, _, err := image.Decode(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user