Skip to content

Commit 1373a95

Browse files
committed
unwrap throwable exception
1 parent ef02978 commit 1373a95

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.time.Instant;
1616
import java.util.Optional;
1717
import java.util.concurrent.CompletableFuture;
18+
import java.util.concurrent.CompletionException;
1819
import java.util.concurrent.CompletionStage;
1920

2021
import javax.annotation.Nullable;
@@ -24,6 +25,7 @@
2425
import org.apache.pekko.japi.pf.ReceiveBuilder;
2526
import org.apache.pekko.persistence.RecoveryCompleted;
2627
import org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel;
28+
import org.eclipse.ditto.base.model.exceptions.DittoInternalErrorException;
2729
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
2830
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeExceptionBuilder;
2931
import org.eclipse.ditto.base.model.headers.DittoHeaders;
@@ -153,7 +155,7 @@ public void onStagedQuery(final Command<?> command, final CompletionStage<WithDi
153155
@Nullable final StartedSpan startedSpan) {
154156
final ActorRef sender = getSender();
155157
response.whenComplete((r, throwable) -> {
156-
if (throwable instanceof DittoRuntimeException dittoRuntimeException) {
158+
if (throwable != null && unwrapThrowable(throwable) instanceof DittoRuntimeException dittoRuntimeException) {
157159
notifySender(sender, dittoRuntimeException);
158160
} else {
159161
doOnQuery(command, r, sender);
@@ -164,6 +166,12 @@ public void onStagedQuery(final Command<?> command, final CompletionStage<WithDi
164166
});
165167
}
166168

169+
private static Throwable unwrapThrowable(final Throwable throwable) {
170+
if (throwable instanceof CompletionException) {
171+
return throwable.getCause() != null ? throwable.getCause() : throwable;
172+
}
173+
return throwable;
174+
}
167175

168176
private void doOnQuery(final Command<?> command, final WithDittoHeaders response, final ActorRef sender) {
169177
if (response.getDittoHeaders().didLiveChannelConditionMatch()) {

0 commit comments

Comments
 (0)