Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug #144: Suppress API error on 404 #145

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions apstra/resource_interface_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,27 @@ type rInterfaceMap struct {

func (o *rInterfaceMap) fetchEmbeddedObjects(ctx context.Context, client *apstra.Client, diags *diag.Diagnostics) (*apstra.LogicalDevice, *apstra.DeviceProfile) {
var ace apstra.ApstraClientErr

// fetch the logical device
ld, err := client.GetLogicalDevice(ctx, apstra.ObjectId(o.LogicalDeviceId.ValueString()))
if err != nil {
if errors.As(err, &ace) && ace.Type() == apstra.ErrNotfound {
diags.AddAttributeError(path.Root("logical_device_id"), errInvalidConfig,
fmt.Sprintf("logical device'%s' not found", o.DeviceProfileId.ValueString()))
fmt.Sprintf("logical device %q not found", o.DeviceProfileId))
} else {
diags.AddError("failed to fetch logical device", err.Error())
}
diags.AddError("error while fetching logical device", err.Error())
}

// fetch the device profile specified by the user
dp, err := client.GetDeviceProfile(ctx, apstra.ObjectId(o.DeviceProfileId.ValueString()))
if err != nil {
if errors.As(err, &ace) && ace.Type() == apstra.ErrNotfound {
diags.AddAttributeError(path.Root("device_profile_id"), errInvalidConfig,
fmt.Sprintf("device profile '%s' not found", o.DeviceProfileId.ValueString()))
fmt.Sprintf("device profile %q not found", o.DeviceProfileId))
} else {
diags.AddError("failed to fetch device profile", err.Error())
}
diags.AddError("error while fetching device profile", err.Error())
}

return ld, dp
Expand All @@ -346,6 +349,7 @@ func (o *rInterfaceMap) ldPortNames(ctx context.Context, diags *diag.Diagnostics
for i, planIntf := range interfaces {
result[i] = planIntf.LogicalDevicePort.ValueString()
}

return result
}

Expand Down