Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
TER-239: Refactor error returns
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Caussat committed Mar 26, 2018
1 parent deb8858 commit 6e0c63f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions ghost/resource_ghost_app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ghost

import (
"fmt"
"log"

"cloud-deploy.io/go-st"
Expand Down Expand Up @@ -458,10 +459,8 @@ func resourceGhostAppCreate(d *schema.ResourceData, meta interface{}) error {
app := expandGhostApp(d)

eveMetadata, err := client.CreateApp(app)
if err == nil {
log.Println("[INFO] App created: " + eveMetadata.ID)
} else {
log.Fatalf("[ERROR] error creating Ghost app: %v", err)
if err != nil {
return fmt.Errorf("[ERROR] error creating Ghost app: %v", err)
}

d.SetId(eveMetadata.ID)
Expand All @@ -473,19 +472,15 @@ func resourceGhostAppRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ghost.Client)

log.Printf("[INFO] Reading Ghost app %s", d.Get("name").(string))
var app ghost.App

app, err := client.GetApp(d.Id())
if err == nil {
log.Println("[INFO] App retrieved: " + d.Id())
} else {
if err != nil {
d.SetId("")
log.Printf("[INFO] App doesn't exist or has been deleted: %v", err)
return nil
return fmt.Errorf("[ERROR] error reading Ghost app: %v", err)
}

if err := flattenGhostApp(d, app); err != nil {
return err
return fmt.Errorf("[ERROR] error reading Ghost app: %v", err)
}

return nil
Expand Down

0 comments on commit 6e0c63f

Please sign in to comment.