Error gracefully when an image is not found on pull. Addresses #50 and comments from #49

This commit is contained in:
Charles Hooper 2013-03-12 05:49:57 +00:00
parent b8219b5275
commit 8e0986caec
2 changed files with 9 additions and 2 deletions

View file

@ -89,7 +89,7 @@ func Pv(src io.Reader, info io.Writer) io.Reader {
// the body of the response. If `stderr` is not nil, a progress bar will be
// written to it.
func Curl(url string, stderr io.Writer) (io.Reader, error) {
curl := exec.Command("curl", "-#", "-L", url)
curl := exec.Command("curl", "-#", "-L", "--fail", url)
output, err := curl.StdoutPipe()
if err != nil {
return nil, err
@ -98,5 +98,8 @@ func Curl(url string, stderr io.Writer) (io.Reader, error) {
if err := curl.Start(); err != nil {
return nil, err
}
if err := curl.Wait(); err != nil {
return nil, err
}
return output, nil
}

View file

@ -428,12 +428,16 @@ func (srv *Server) CmdPull(stdin io.ReadCloser, stdout io.Writer, args ...string
}
fmt.Fprintf(stdout, "Downloading from %s\n", u.String())
// Download with curl (pretty progress bar)
// If curl is not available, fallback to http.Get()
// If curl is not available or receives a HTTP error, fallback
// to http.Get()
archive, err := future.Curl(u.String(), stdout)
if err != nil {
if resp, err := http.Get(u.String()); err != nil {
return err
} else {
if resp.StatusCode >= 400 {
return errors.New("Got HTTP status code >= 400: " + resp.Status)
}
archive = resp.Body
}
}