Skip to content

Commit ce8d94f

Browse files
committedMar 4, 2025·
unwrap throwable exception
1 parent ef02978 commit ce8d94f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎internal/utils/persistent-actors/src/main/java/org/eclipse/ditto/internal/utils/persistentactors/AbstractPersistenceActor.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ public void onStagedQuery(final Command<?> command, final CompletionStage<WithDi
817817
if (command.getDittoHeaders().isResponseRequired()) {
818818
final ActorRef sender = getSender();
819819
response.whenComplete((r, throwable) -> {
820-
if (throwable instanceof DittoRuntimeException dittoRuntimeException) {
820+
if (unwrapThrowable(throwable) instanceof DittoRuntimeException dittoRuntimeException) {
821821
notifySender(sender, dittoRuntimeException);
822822
} else {
823823
notifySender(sender, r);
@@ -840,6 +840,21 @@ public void onError(final DittoRuntimeException error, final Command<?> errorCau
840840
}
841841
}
842842

843+
/**
844+
* Unwraps the root cause of the given {@link Throwable} if it is wrapped inside a {@link CompletionException}.
845+
*
846+
* @param throwable The throwable to unwrap.
847+
* @return The unwrapped cause if the throwable is a {@link CompletionException} and has a cause,
848+
* otherwise returns the original throwable.
849+
*/
850+
protected static Throwable unwrapThrowable(final Throwable throwable) {
851+
if (throwable != null && throwable instanceof CompletionException) {
852+
return throwable.getCause() != null ? throwable.getCause() : throwable;
853+
}
854+
return throwable;
855+
}
856+
857+
843858
/**
844859
* Send a reply and increment access counter.
845860
*

‎things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/ThingPersistenceActor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void onStagedQuery(final Command<?> command, final CompletionStage<WithDi
153153
@Nullable final StartedSpan startedSpan) {
154154
final ActorRef sender = getSender();
155155
response.whenComplete((r, throwable) -> {
156-
if (throwable instanceof DittoRuntimeException dittoRuntimeException) {
156+
if (unwrapThrowable(throwable) instanceof DittoRuntimeException dittoRuntimeException) {
157157
notifySender(sender, dittoRuntimeException);
158158
} else {
159159
doOnQuery(command, r, sender);

0 commit comments

Comments
 (0)
Please sign in to comment.