diff --git a/app/vmbackup/snapshot/snapshot.go b/app/vmbackup/snapshot/snapshot.go index 63c2d9ce4..199d21114 100644 --- a/app/vmbackup/snapshot/snapshot.go +++ b/app/vmbackup/snapshot/snapshot.go @@ -25,16 +25,17 @@ func Create(createSnapshotURL string) (string, error) { if err != nil { return "", err } - resp, err := http.Get(u.String()) if err != nil { return "", err } - body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } + if resp.StatusCode != http.StatusOK { + return "", fmt.Errorf("unexpected status code returned from %q; expecting %d; got %d; response body: %q", createSnapshotURL, resp.StatusCode, http.StatusOK, body) + } snap := snapshot{} err = json.Unmarshal(body, &snap) @@ -58,21 +59,21 @@ func Delete(deleteSnapshotURL string, snapshotName string) error { formData := url.Values{ "snapshot": {snapshotName}, } - u, err := url.Parse(deleteSnapshotURL) if err != nil { return err } - resp, err := http.PostForm(u.String(), formData) if err != nil { return err } - body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code returned from %q; expecting %d; got %d; response body: %q", deleteSnapshotURL, resp.StatusCode, http.StatusOK, body) + } snap := snapshot{} err = json.Unmarshal(body, &snap)