Skip to content

Commit

Permalink
consider returnNullOn before throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
aozarov authored and mziccard committed Apr 27, 2016
1 parent 72b8533 commit 55df976
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
import org.joda.time.Duration;

import java.io.IOException;
import java.util.Set;
import java.util.concurrent.Future;

import autovalue.shaded.com.google.common.common.collect.Sets;
import io.grpc.Status.Code;

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

private static <V> Future<V> translate(ListenableFuture<V> from, final boolean idempotent,
final int... returnNullOn) {
int... returnNullOn) {
final Set<Integer> returnNullOnSet = Sets.newHashSetWithExpectedSize(returnNullOn.length);
for (int value : returnNullOn) {
returnNullOnSet.add(value);
}
return Futures.catching(from, ApiException.class, new Function<ApiException, V>() {
@Override
public V apply(ApiException exception) {
if (returnNullOnSet.contains(exception.getStatusCode().value())) {
return null;
}
throw new PubSubException(exception, idempotent);
}
});
Expand Down

0 comments on commit 55df976

Please sign in to comment.