public static boolean isRetryable(Throwable error) { if (!(error instanceof ApiException)) { return true; } ApiException apiException = (ApiException) error; switch (apiException.getStatusCode().getCode()) { case DEADLINE_EXCEEDED: case INTERNAL: case CANCELLED: case RESOURCE_EXHAUSTED: case ABORTED: return true; case UNAVAILABLE: // TODO(pongad): check that ApiException propagate message properly. return !apiException.getMessage().contains("Server shutdownNow invoked"); default: return false; } } }
public static Status statusFromApiException(ApiException exception) { if (exception.getStatusCode().getTransportCode() instanceof io.grpc.Status) { io.grpc.Status grpcStatus = (io.grpc.Status) exception.getStatusCode().getTransportCode(); return StatusConverter.fromGrpcStatus(grpcStatus); } return Status.UNKNOWN.withDescription(exception.getMessage()); } }
@BetaApi public BaseGrpcServiceException(ApiException apiException) { super( ExceptionData.newBuilder() .setMessage(apiException.getMessage()) .setCause(apiException) .setRetryable(apiException.isRetryable()) .setCode(apiException.getStatusCode().getCode().getHttpStatusCode()) .setReason(apiException.getStatusCode().getCode().name()) .setLocation(null) .setDebugInfo(null) .build()); } }
public static Status statusFromApiException(ApiException exception) { if (exception.getStatusCode().getTransportCode() instanceof io.grpc.Status) { io.grpc.Status grpcStatus = (io.grpc.Status) exception.getStatusCode().getTransportCode(); return StatusConverter.fromGrpcStatus(grpcStatus); } return Status.UNKNOWN.withDescription(exception.getMessage()); } }
private void assertFutureFailMetaSuccess( OperationFuture<Color, Currency> future, Currency meta, FakeStatusCode statusCode, String errorMessage) throws TimeoutException, InterruptedException, ExecutionException { Exception exception = null; try { future.get(3, TimeUnit.SECONDS); } catch (ExecutionException e) { exception = e; } assertThat(exception).isNotNull(); assertExceptionMatchesCode(statusCode, exception.getCause()); ApiException cause = (ApiException) exception.getCause(); assertThat(cause.getStatusCode()).isEqualTo(statusCode); assertThat(cause.getMessage()).isEqualTo(errorMessage); assertThat(future.isDone()).isTrue(); assertThat(future.isCancelled()).isFalse(); Truth.assertThat(future.peekMetadata().get()).isEqualTo(meta); assertThat(future.peekMetadata()).isSameAs(future.peekMetadata()); assertThat(future.peekMetadata().isDone()).isTrue(); assertThat(future.peekMetadata().isCancelled()).isFalse(); Truth.assertThat(future.getMetadata().get()).isEqualTo(meta); assertThat(future.getMetadata()).isSameAs(future.getMetadata()); assertThat(future.getMetadata().isDone()).isTrue(); assertThat(future.getMetadata().isCancelled()).isFalse(); }
@BetaApi public BaseGrpcServiceException(ApiException apiException) { super( ExceptionData.newBuilder() .setMessage(apiException.getMessage()) .setCause(apiException) .setRetryable(apiException.isRetryable()) .setCode(apiException.getStatusCode().getCode().getHttpStatusCode()) .setReason(apiException.getStatusCode().getCode().name()) .setLocation(null) .setDebugInfo(null) .build()); } }