|
34 | 34 | import io.grpc.StatusRuntimeException; |
35 | 35 | import java.time.Duration; |
36 | 36 | import java.util.concurrent.CompletableFuture; |
| 37 | +import java.util.concurrent.CompletionException; |
| 38 | +import java.util.concurrent.ExecutionException; |
37 | 39 | import java.util.concurrent.ThreadLocalRandom; |
38 | 40 |
|
39 | 41 | /** A callable to fork traffic between classic and session based operations. */ |
@@ -110,15 +112,25 @@ private boolean useExperimental(ReqT req) { |
110 | 112 | } |
111 | 113 |
|
112 | 114 | 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 | + |
113 | 124 | Status.Code code = Status.Code.UNKNOWN; |
114 | 125 |
|
115 | | - if (e instanceof StatusRuntimeException) { |
116 | | - code = ((StatusRuntimeException) e).getStatus().getCode(); |
| 126 | + if (cause instanceof StatusRuntimeException) { |
| 127 | + code = ((StatusRuntimeException) cause).getStatus().getCode(); |
117 | 128 | } |
118 | | - if (e instanceof StatusException) { |
119 | | - code = ((StatusException) e).getStatus().getCode(); |
| 129 | + if (cause instanceof StatusException) { |
| 130 | + code = ((StatusException) cause).getStatus().getCode(); |
120 | 131 | } |
121 | 132 |
|
122 | | - return ApiExceptionFactory.createException(e.getMessage(), e, GrpcStatusCode.of(code), false); |
| 133 | + return ApiExceptionFactory.createException( |
| 134 | + cause.getMessage(), e, GrpcStatusCode.of(code), false); |
123 | 135 | } |
124 | 136 | } |
0 commit comments