Skip to content

Commit d61a16e

Browse files
committed
Cope with an object that was deleted server-side
1 parent 5331916 commit d61a16e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

restapi/api_object.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ func (obj *api_object) read_object() error {
231231

232232
res_str, err := obj.api_client.send_request(obj.api_client.read_method, strings.Replace(obj.get_path, "{id}", obj.id, -1), "")
233233
if err != nil {
234+
if strings.Contains(err.Error(), "Unexpected response code '404'") {
235+
log.Printf("api_object.go: 404 error while refreshing state for '%s' at path '%s'. Removing from state.", obj.id, obj.get_path)
236+
obj.id = ""
237+
return nil
238+
}
234239
return err
235240
}
236241

restapi/api_object_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ func TestAPIObject(t *testing.T) {
218218
}
219219
testing_objects["pet"].delete_object()
220220
err = testing_objects["pet"].read_object()
221-
if err == nil {
222-
t.Fatalf("api_object_test.go: 'pet' object deleted, but 404 not returned when getting it.\n")
221+
if err != nil {
222+
t.Fatalf("api_object_test.go: 'pet' object deleted, but an error was returned when reading the object (expected the provider to cope with this!\n")
223223
}
224224
})
225225

0 commit comments

Comments
 (0)