Skip to content

Commit 55df976

Browse files
aozarovmziccard
authored andcommitted
consider returnNullOn before throwing
1 parent 72b8533 commit 55df976

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

gcloud-java-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454
import org.joda.time.Duration;
5555

5656
import java.io.IOException;
57+
import java.util.Set;
5758
import java.util.concurrent.Future;
5859

60+
import autovalue.shaded.com.google.common.common.collect.Sets;
5961
import io.grpc.Status.Code;
6062

6163
public class DefaultPubSubRpc implements PubSubRpc {
@@ -98,10 +100,17 @@ private static ApiCallSettings.Builder apiCallSettings(PubSubOptions options) {
98100
}
99101

100102
private static <V> Future<V> translate(ListenableFuture<V> from, final boolean idempotent,
101-
final int... returnNullOn) {
103+
int... returnNullOn) {
104+
final Set<Integer> returnNullOnSet = Sets.newHashSetWithExpectedSize(returnNullOn.length);
105+
for (int value : returnNullOn) {
106+
returnNullOnSet.add(value);
107+
}
102108
return Futures.catching(from, ApiException.class, new Function<ApiException, V>() {
103109
@Override
104110
public V apply(ApiException exception) {
111+
if (returnNullOnSet.contains(exception.getStatusCode().value())) {
112+
return null;
113+
}
105114
throw new PubSubException(exception, idempotent);
106115
}
107116
});

0 commit comments

Comments
 (0)