Skip to content

Commit b01bb9f

Browse files
committed
resource_{domain,email_forward}: Return 404s to the user
- Previously the for loop just carried on when it got a 404 error back that the resource didn't exist. This actually returns that error to the user.
1 parent 57289b7 commit b01bb9f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

improvmx/resource_domain.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package improvmx
22

33
import (
4+
"fmt"
45
"log"
56
"time"
67

@@ -47,6 +48,11 @@ func resourceDomainCreate(d *schema.ResourceData, meta interface{}) error {
4748
time.Sleep(10 * time.Second)
4849
}
4950

51+
if resp.Code == 404 {
52+
log.Printf("[DEBUG] Couldn't find the resource in ImprovMX. Aborting")
53+
return fmt.Errorf("HTTP response code %d, error text: %s", resp.Code, resp.Errors.Domain)
54+
}
55+
5056
if resp.Success {
5157
return resourceDomainRead(d, meta)
5258
}
@@ -68,6 +74,11 @@ func resourceDomainRead(d *schema.ResourceData, meta interface{}) error {
6874
time.Sleep(10 * time.Second)
6975
}
7076

77+
if resp.Code == 404 {
78+
log.Printf("[DEBUG] Couldn't find the resource in ImprovMX. Aborting")
79+
return fmt.Errorf("HTTP response code %d, error text: %s", resp.Code, resp.Errors.Domain)
80+
}
81+
7182
if resp.Success {
7283
d.SetId(resp.Domain.Domain)
7384
d.Set("domain", resp.Domain.Domain)
@@ -92,6 +103,11 @@ func resourceDomainUpdate(d *schema.ResourceData, meta interface{}) error {
92103
time.Sleep(10 * time.Second)
93104
}
94105

106+
if resp.Code == 404 {
107+
log.Printf("[DEBUG] Couldn't find the resource in ImprovMX. Aborting")
108+
return fmt.Errorf("HTTP response code %d, error text: %s", resp.Code, resp.Errors.Domain)
109+
}
110+
95111
if resp.Success {
96112
return resourceDomainRead(d, meta)
97113
}

improvmx/resource_email_forward.go

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func resourceEmailForwardRead(d *schema.ResourceData, meta interface{}) error {
6161
time.Sleep(10 * time.Second)
6262
}
6363

64+
if resp.Code == 404 {
65+
log.Printf("[DEBUG] Couldn't find the resource in ImprovMX. Aborting")
66+
return fmt.Errorf("HTTP response code %d, error text: %s", resp.Code, resp.Errors.Domain)
67+
}
68+
6469
if resp.Success {
6570
d.SetId(strconv.FormatInt(resp.Alias.Id, 10))
6671
d.Set("alias_name", resp.Alias.Alias)
@@ -84,6 +89,11 @@ func resourceEmailForwardUpdate(d *schema.ResourceData, meta interface{}) error
8489
time.Sleep(10 * time.Second)
8590
}
8691

92+
if resp.Code == 404 {
93+
log.Printf("[DEBUG] Couldn't find the resource in ImprovMX. Aborting")
94+
return fmt.Errorf("HTTP response code %d, error text: %s", resp.Code, resp.Errors.Domain)
95+
}
96+
8797
if resp.Success {
8898
return resourceEmailForwardRead(d, meta)
8999
}

0 commit comments

Comments
 (0)