Skip to content

Commit 2742460

Browse files
authored
fix: fix translate exception in compat layer (googleapis#2879)
Change-Id: I23d2c4103d4459f4d5cdceab22cae8d5ba5cd64d
1 parent cb56060 commit 2742460

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/compat/ops/DivertingUnaryCallable.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import io.grpc.StatusRuntimeException;
3535
import java.time.Duration;
3636
import java.util.concurrent.CompletableFuture;
37+
import java.util.concurrent.CompletionException;
38+
import java.util.concurrent.ExecutionException;
3739
import java.util.concurrent.ThreadLocalRandom;
3840

3941
/** A callable to fork traffic between classic and session based operations. */
@@ -110,15 +112,25 @@ private boolean useExperimental(ReqT req) {
110112
}
111113

112114
ApiException translateException(Throwable e) {
115+
Throwable cause = e;
116+
while (cause instanceof CompletionException || cause instanceof ExecutionException) {
117+
if (cause.getCause() != null) {
118+
cause = cause.getCause();
119+
} else {
120+
break;
121+
}
122+
}
123+
113124
Status.Code code = Status.Code.UNKNOWN;
114125

115-
if (e instanceof StatusRuntimeException) {
116-
code = ((StatusRuntimeException) e).getStatus().getCode();
126+
if (cause instanceof StatusRuntimeException) {
127+
code = ((StatusRuntimeException) cause).getStatus().getCode();
117128
}
118-
if (e instanceof StatusException) {
119-
code = ((StatusException) e).getStatus().getCode();
129+
if (cause instanceof StatusException) {
130+
code = ((StatusException) cause).getStatus().getCode();
120131
}
121132

122-
return ApiExceptionFactory.createException(e.getMessage(), e, GrpcStatusCode.of(code), false);
133+
return ApiExceptionFactory.createException(
134+
cause.getMessage(), e, GrpcStatusCode.of(code), false);
123135
}
124136
}

0 commit comments

Comments
 (0)