Commit 341cfb2c authored by Jack Pearkes's avatar Jack Pearkes

builder/digitalocean: improve error messages from DO api

parent 477ac8cd
......@@ -156,7 +156,7 @@ func NewRequest(d DigitalOceanClient, path string, params string) (map[string]in
// Catch all non-200 status and return an error
if resp.StatusCode != 200 {
err = errors.New(fmt.Sprintf("recieved non-200 status from digitalocean: %d", resp.StatusCode))
err = errors.New(fmt.Sprintf("Recieved non-200 HTTP status from DigitalOcean: %d", resp.StatusCode))
log.Printf("response from digital ocean: %v", decodedResponse)
return decodedResponse, err
}
......@@ -170,7 +170,11 @@ func NewRequest(d DigitalOceanClient, path string, params string) (map[string]in
// Catch all non-OK statuses from DO and return an error
status := decodedResponse["status"]
if status != "OK" {
err = errors.New(fmt.Sprintf("recieved non-OK status from digitalocean: %d", status))
// Get the actual error message if there is one
if status == "ERROR" {
status = decodedResponse["error_message"]
}
err = errors.New(fmt.Sprintf("Recieved bad status from DigitalOcean: %v", status))
log.Printf("response from digital ocean: %v", decodedResponse)
return decodedResponse, err
}
......
......@@ -63,8 +63,11 @@ func (s *stepCreateDroplet) Cleanup(state map[string]interface{}) {
err := client.DestroyDroplet(s.dropletId)
curlstr := fmt.Sprintf("curl '%v/droplets/%v/destroy?client_id=%v&api_key=%v'",
DIGITALOCEAN_API_URL, s.dropletId, c.ClientID, c.APIKey)
if err != nil {
ui.Error(fmt.Sprintf(
"Error destroying droplet. Please destroy it manually: %v", s.dropletId))
"Error destroying droplet. Please destroy it manually: %v", curlstr))
}
}
......@@ -71,12 +71,17 @@ func (s *stepCreateSSHKey) Cleanup(state map[string]interface{}) {
client := state["client"].(*DigitalOceanClient)
ui := state["ui"].(packer.Ui)
c := state["config"].(config)
ui.Say("Deleting temporary ssh key...")
err := client.DestroyKey(s.keyId)
curlstr := fmt.Sprintf("curl '%v/ssh_keys/%v/destroy?client_id=%v&api_key=%v'",
DIGITALOCEAN_API_URL, s.keyId, c.ClientID, c.APIKey)
if err != nil {
log.Printf("Error cleaning up ssh key: %v", err.Error())
ui.Error(fmt.Sprintf(
"Error cleaning up ssh key. Please delete the key manually: %v", s.keyId))
"Error cleaning up ssh key. Please delete the key manually: %v", curlstr))
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment