Skip to content

Commit 4501da2

Browse files
author
Harald Krämer
committed
fix: the aipe can return 410 for deleted objects instead of 404, which trips up the provider
1 parent ecb1dee commit 4501da2

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

internal/aipe/api_error.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ func (e *ApiError) Error() string {
1717
return e.Message
1818
}
1919

20-
func ErrorIs404(err error) bool {
20+
func ErrorIsNotFound(err error) bool {
2121
apiError, ok := errwrap.GetType(err, &ApiError{}).(*ApiError)
2222

23-
tflog.Info(context.TODO(), "ErrorIs404", map[string]interface{}{"apiError": apiError, "ok": ok})
23+
tflog.Info(context.TODO(), "ErrorIsNotFound", map[string]interface{}{"apiError": apiError, "ok": ok})
2424

25-
return ok && apiError != nil && apiError.StatusCode == http.StatusNotFound
25+
return ok && apiError != nil && (apiError.StatusCode == http.StatusNotFound || apiError.StatusCode == http.StatusGone)
2626
}

internal/provider/data_object_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (d *DataObjectDataSource) Read(ctx context.Context, req datasource.ReadRequ
8383
tflog.Info(ctx, "Reading data source")
8484
object, err := d.client.GetObject(ctx, data.Id.ValueString())
8585
if err != nil {
86-
if aipe.ErrorIs404(err) {
86+
if aipe.ErrorIsNotFound(err) {
8787
resp.State.RemoveResource(ctx)
8888
return
8989
}

internal/provider/data_object_resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (r *DataObjectResource) Read(ctx context.Context, req resource.ReadRequest,
115115
tflog.Info(ctx, "Reading data source", map[string]interface{}{"id": data.Id.ValueString()})
116116
object, err := r.client.GetObject(ctx, data.Id.ValueString())
117117
if err != nil {
118-
if aipe.ErrorIs404(err) {
118+
if aipe.ErrorIsNotFound(err) {
119119
resp.State.RemoveResource(ctx)
120120
return
121121
}
@@ -173,7 +173,7 @@ func (r *DataObjectResource) Delete(ctx context.Context, req resource.DeleteRequ
173173
tflog.Info(ctx, "Deleting data source", map[string]interface{}{"id": data.Id.ValueString()})
174174
err := r.client.DeleteObject(ctx, data.Id.ValueString())
175175
if err != nil {
176-
if aipe.ErrorIs404(err) {
176+
if aipe.ErrorIsNotFound(err) {
177177
return
178178
}
179179
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete example, got error: %s", err))

0 commit comments

Comments
 (0)