diff --git a/api.go b/api.go index 3164a886f6..e5816b255f 100644 --- a/api.go +++ b/api.go @@ -295,7 +295,8 @@ func postImagesCreate(srv *Server, version float64, w http.ResponseWriter, r *ht w.Header().Set("Content-Type", "application/json") } if err := srv.ImagePull(image, tag, registry, w, version > 1.0); err != nil { - return err + fmt.Fprintf(w, utils.FormatError(err.Error(), version > 1.0)) + return nil } } else { //import if err := srv.ImageImport(src, repo, tag, r.Body, w); err != nil { diff --git a/commands.go b/commands.go index 6c4dcd14d6..01ab8a334f 100644 --- a/commands.go +++ b/commands.go @@ -1261,6 +1261,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e type Message struct { Status string `json:"status,omitempty"` Progress string `json:"progress,omitempty"` + Error string `json:"error,omitempty"` } dec := json.NewDecoder(resp.Body) for { @@ -1272,6 +1273,8 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e } if m.Progress != "" { fmt.Fprintf(out, "Downloading %s\r", m.Progress) + } else if m.Error != "" { + return fmt.Errorf(m.Error) } else { fmt.Fprintf(out, "%s\n", m.Status) } diff --git a/utils/utils.go b/utils/utils.go index 233c624b68..8588c52478 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -564,6 +564,13 @@ func FormatStatus(str string, json bool) string { return str + "\r\n" } +func FormatError(str string, json bool) string { + if json { + return "{\"error\" : \"" + str + "\"}" + } + return "Error: " + str + "\r\n" +} + func FormatProgress(str string, json bool) string { if json { return "{\"progress\" : \"" + str + "\"}"