Skip to content

Commit

Permalink
[fix][admin] Fix exception loss in getMessageId method (#23766)
Browse files Browse the repository at this point in the history
Co-authored-by: houbonan <[email protected]>
(cherry picked from commit 3d50574)
  • Loading branch information
danpi authored and lhotari committed Dec 21, 2024
1 parent d3d8e50 commit dfc7d24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2774,17 +2774,18 @@ protected CompletableFuture<Response> internalGetMessageById(long ledgerId, long
public void readEntryFailed(ManagedLedgerException exception,
Object ctx) {
if (exception instanceof ManagedLedgerException.LedgerNotExistException) {
throw new RestException(Status.NOT_FOUND, "Message id not found");
results.completeExceptionally(
new RestException(Status.NOT_FOUND, "Message id not found"));
}
throw new RestException(exception);
results.completeExceptionally(new RestException(exception));
}

@Override
public void readEntryComplete(Entry entry, Object ctx) {
try {
results.complete(generateResponseWithEntry(entry, (PersistentTopic) topic));
} catch (IOException exception) {
throw new RestException(exception);
results.completeExceptionally(new RestException(exception));
} finally {
if (entry != null) {
entry.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,10 @@ public void testGetMessageById() throws Exception {
Assert.expectThrows(PulsarAdminException.NotFoundException.class, () -> {
admin.topics().getMessageById(topicName1, id2.getLedgerId(), id2.getEntryId());
});

Assert.expectThrows(PulsarAdminException.ServerSideErrorException.class, () -> {
admin.topics().getMessageById(topicName1, id1.getLedgerId(), id1.getEntryId() + 10);
});
}

@Test
Expand Down

0 comments on commit dfc7d24

Please sign in to comment.