Skip to content

Commit 983b73d

Browse files
Shawyeoklhotari
authored andcommitted
[improve][client] Enhance error handling for non-exist subscription in consumer creation (#23254)
(cherry picked from commit 7fc88d6)
1 parent e0523ac commit 983b73d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: pulsar-broker/src/test/java/org/apache/pulsar/client/api/MultiTopicsConsumerTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ public void testSubscriptionNotFound() throws PulsarAdminException, PulsarClient
413413
.isAckReceiptEnabled(true)
414414
.subscribe();
415415
assertTrue(singleTopicConsumer instanceof ConsumerImpl);
416+
} catch (PulsarClientException.SubscriptionNotFoundException ignore) {
416417
} catch (Throwable t) {
417-
assertTrue(t.getCause().getCause() instanceof PulsarClientException.SubscriptionNotFoundException);
418+
fail("Should throw PulsarClientException.SubscriptionNotFoundException instead");
418419
}
419420

420421
try {
@@ -424,8 +425,9 @@ public void testSubscriptionNotFound() throws PulsarAdminException, PulsarClient
424425
.isAckReceiptEnabled(true)
425426
.subscribe();
426427
assertTrue(multiTopicsConsumer instanceof MultiTopicsConsumerImpl);
428+
} catch (PulsarClientException.SubscriptionNotFoundException ignore) {
427429
} catch (Throwable t) {
428-
assertTrue(t.getCause().getCause() instanceof PulsarClientException.SubscriptionNotFoundException);
430+
fail("Should throw PulsarClientException.SubscriptionNotFoundException instead");
429431
}
430432

431433
pulsar.getConfiguration().setAllowAutoSubscriptionCreation(true);

Diff for: pulsar-client-api/src/main/java/org/apache/pulsar/client/api/PulsarClientException.java

+2
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ public static PulsarClientException unwrap(Throwable t) {
11441144
newException = new TransactionConflictException(msg);
11451145
} else if (cause instanceof TopicDoesNotExistException) {
11461146
newException = new TopicDoesNotExistException(msg);
1147+
} else if (cause instanceof SubscriptionNotFoundException) {
1148+
newException = new SubscriptionNotFoundException(msg);
11471149
} else if (cause instanceof ProducerFencedException) {
11481150
newException = new ProducerFencedException(msg);
11491151
} else if (cause instanceof MemoryBufferIsFullError) {

0 commit comments

Comments
 (0)