From 5b8f6cc65a60e42d6791e8e3d5a85bbd2e2dffb3 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Tue, 9 Apr 2024 07:55:17 +0200 Subject: [PATCH] fix(bindings): adjust errorhandling for service instances (#29) --- src/clients/Dim.Clients/Api/Cf/CfClient.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/clients/Dim.Clients/Api/Cf/CfClient.cs b/src/clients/Dim.Clients/Api/Cf/CfClient.cs index b4374e9..30c1f82 100644 --- a/src/clients/Dim.Clients/Api/Cf/CfClient.cs +++ b/src/clients/Dim.Clients/Api/Cf/CfClient.cs @@ -121,7 +121,7 @@ public async Task GetServicePlan(string servicePlanName, string servicePla x.BrokerCatalog?.BrokerCatalogMetadata?.AutoSubscription?.AppName == servicePlanName); if (servicePlans.Count() != 1) { - throw new ServiceException($"There must be exactly one service plan with name {servicePlanName} and type {servicePlanType}"); + throw new ServiceException($"There must be exactly one service plan with name {servicePlanName} and type {servicePlanType}", isRecoverable: !servicePlans.Any()); } return servicePlans.Single().Id; @@ -152,7 +152,7 @@ public async Task GetSpace(string tenantName, CancellationToken cancellati var spaces = response.Resources.Where(x => x.Name == spaceName); if (spaces.Count() != 1) { - throw new ServiceException($"There must be exactly one space with name {spaceName}"); + throw new ServiceException($"There must be exactly one space with name {spaceName}", isRecoverable: !spaces.Any()); } return spaces.Single().Id; @@ -197,7 +197,7 @@ private async Task GetServiceInstances(string tenantName, Guid? spaceId, C var resources = response.Resources.Where(x => x.Name == name && x.Type == "managed" && (spaceId == null || x.Relationships.Space.Data.Id == spaceId.Value) && x.LastOperation.State == "succeeded"); if (resources.Count() != 1) { - throw new ServiceException($"There must be exactly one service instance"); + throw new ServiceException("There must be exactly one service instance", isRecoverable: !resources.Any()); } return resources.Single().Id; @@ -241,7 +241,7 @@ public async Task GetServiceBinding(string tenantName, Guid spaceId, strin var resources = response.Resources.Where(x => x.Relationships.ServiceInstance.Data.Id == serviceInstanceId); if (resources.Count() != 1) { - throw new ServiceException($"There must be exactly one service credential binding"); + throw new ServiceException("There must be exactly one service credential binding", isRecoverable: !resources.Any()); } return resources.Single().Id; @@ -265,7 +265,7 @@ public async Task GetServiceBindingDetai if (response == null) { - throw new ServiceException($"There must be exactly one service instance"); + throw new ServiceException("There must be exactly one service instance", isRecoverable: true); } return response;