Skip to content

Commit

Permalink
Review fixes:
Browse files Browse the repository at this point in the history
changed content of failed future in case of ApiException

Signed-off-by: Matthias Kaemmer <[email protected]>
  • Loading branch information
mattkaem committed Oct 4, 2023
1 parent f3c0f2b commit cad74c0
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -120,7 +121,8 @@ private Future<String> 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));
}
}

Expand All @@ -135,7 +137,8 @@ private Future<String> 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));
}
}

Expand Down Expand Up @@ -163,7 +166,8 @@ private Future<String> 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));
}
}

Expand All @@ -189,13 +193,15 @@ private Future<String> 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() {
Expand Down

0 comments on commit cad74c0

Please sign in to comment.