From 72b66f43ec8ba6fd4288799c7f9ff59e851432b7 Mon Sep 17 00:00:00 2001 From: Matthias Kaemmer Date: Wed, 4 Oct 2023 15:46:49 +0200 Subject: [PATCH] Review fixes: changed content of failed future in case of ApiException Signed-off-by: Matthias Kaemmer --- .../pubsub/PubSubBasedAdminClientManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/clients/pubsub-common/src/main/java/org/eclipse/hono/client/pubsub/PubSubBasedAdminClientManager.java b/clients/pubsub-common/src/main/java/org/eclipse/hono/client/pubsub/PubSubBasedAdminClientManager.java index 2cc38446e1..77e88cc0e8 100644 --- a/clients/pubsub-common/src/main/java/org/eclipse/hono/client/pubsub/PubSubBasedAdminClientManager.java +++ b/clients/pubsub-common/src/main/java/org/eclipse/hono/client/pubsub/PubSubBasedAdminClientManager.java @@ -16,6 +16,7 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; +import org.eclipse.hono.client.ServerErrorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -120,7 +121,8 @@ private Future getTopic(final TopicName topic, final TopicAdminClient cl try { return Future.succeededFuture(client.getTopic(topic).getName()); } catch (ApiException e) { - return Future.failedFuture(String.format("Could not get topic. %s", e)); + return Future.failedFuture( + new ServerErrorException(503, String.format("Could not get topic %s.", topic.getTopic()), e)); } } @@ -135,7 +137,8 @@ private Future createTopic(final String projectId, final TopicName topic return Future.succeededFuture(topic.getTopic()); } catch (ApiException e) { LOG.debug("Error creating topic {} on project {}", topic, projectId, e); - return Future.failedFuture(String.format("Topic creation failed. %s", e)); + return Future.failedFuture(new ServerErrorException(503, + String.format("Topic creation failed for topic %s.", topic.getTopic()), e)); } } @@ -163,7 +166,8 @@ private Future getSubscription(final SubscriptionName subscription, fina try { return Future.succeededFuture(client.getSubscription(subscription).getName()); } catch (ApiException e) { - return Future.failedFuture(String.format("Could not get subscription. %s", e)); + return Future.failedFuture(new ServerErrorException(503, + String.format("Could not get subscription %s.", subscription.getSubscription()), e)); } } @@ -189,13 +193,15 @@ private Future createSubscription(final String projectId, final Subscrip return Future.succeededFuture(subscription.getSubscription()); } catch (ApiException e) { LOG.debug("Error creating subscription {} for topic {} on project {}", subscription, topic, projectId, e); - return Future.failedFuture(String.format("Subscription creation failed. %s", e)); + return Future.failedFuture(new ServerErrorException(503, + String.format("Subscription creation failed for subscription %s.", subscription.getSubscription()), + e)); } } /** * Closes the TopicAdminClient and the SubscriptionAdminClient if they exist. This method is expected to be invoked - * as soon as the TopicAdminClient and the SubscriptionAdminClient is no longer needed. This method will bock the + * as soon as the TopicAdminClient and the SubscriptionAdminClient is no longer needed. This method will block the * current thread for up to 10 seconds! */ public void closeAdminClients() {