|
37 | 37 | import com.google.common.collect.Iterables; |
38 | 38 | import com.google.common.collect.Lists; |
39 | 39 | import com.google.common.collect.Maps; |
| 40 | +import com.google.common.collect.Sets; |
| 41 | +import com.google.common.primitives.Ints; |
40 | 42 | import com.google.gcloud.BaseService; |
41 | 43 | import com.google.gcloud.ExceptionHandler; |
42 | 44 | import com.google.gcloud.ExceptionHandler.Interceptor; |
|
52 | 54 | import java.util.Arrays; |
53 | 55 | import java.util.List; |
54 | 56 | import java.util.Map; |
| 57 | +import java.util.Set; |
55 | 58 | import java.util.concurrent.Callable; |
56 | 59 |
|
57 | 60 | final class StorageServiceImpl extends BaseService<StorageServiceOptions> implements StorageService { |
@@ -325,20 +328,28 @@ public BatchResponse apply(BatchRequest batchRequest) { |
325 | 328 | List<BatchResponse.Result<Blob>> updates = transformBatchResult( |
326 | 329 | toUpdate, response.updates, Blob.FROM_PB_FUNCTION); |
327 | 330 | List<BatchResponse.Result<Blob>> gets = transformBatchResult( |
328 | | - toGet, response.gets, Blob.FROM_PB_FUNCTION); |
| 331 | + toGet, response.gets, Blob.FROM_PB_FUNCTION, 404); |
329 | 332 | return new BatchResponse(deletes, updates, gets); |
330 | 333 | } |
331 | 334 |
|
332 | 335 | private <I, O extends Serializable> List<BatchResponse.Result<O>> transformBatchResult( |
333 | 336 | Iterable<Tuple<StorageObject, Map<StorageRpc.Option, ?>>> request, |
334 | | - Map<StorageObject, Tuple<I, StorageServiceException>> results, Function<I, O> transform) { |
| 337 | + Map<StorageObject, Tuple<I, StorageServiceException>> results, Function<I, O> transform, |
| 338 | + int... nullOnErrorCodes) { |
| 339 | + Set nullOnErrorCodesSet = Sets.newHashSet(Ints.asList(nullOnErrorCodes)); |
335 | 340 | List<BatchResponse.Result<O>> response = Lists.newArrayListWithCapacity(results.size()); |
336 | 341 | for (Tuple<StorageObject, ?> tuple : request) { |
337 | 342 | Tuple<I, StorageServiceException> result = results.get(tuple.x()); |
338 | 343 | if (result.x() != null) { |
339 | 344 | response.add(new BatchResponse.Result<>(transform.apply(result.x()))); |
340 | 345 | } else { |
341 | | - response.add(new BatchResponse.Result<O>(result.y())); |
| 346 | + StorageServiceException exception = result.y(); |
| 347 | + if (nullOnErrorCodesSet.contains(exception.code())) { |
| 348 | + //noinspection unchecked |
| 349 | + response.add(BatchResponse.Result.<O>empty()); |
| 350 | + } else { |
| 351 | + response.add(new BatchResponse.Result<O>(result.y())); |
| 352 | + } |
342 | 353 | } |
343 | 354 | } |
344 | 355 | return response; |
|
0 commit comments