@@ -187,8 +187,15 @@ public PutObjectResponse putObject(PutObjectRequest putObjectRequest, RequestBod
187
187
.secureRandom (_secureRandom )
188
188
.build ();
189
189
190
- CompletableFuture <PutObjectResponse > futurePut = pipeline .putObject (putObjectRequest , AsyncRequestBody .fromInputStream (requestBody .contentStreamProvider ().newStream (), requestBody .optionalContentLength ().orElse (-1L ), Executors .newSingleThreadExecutor ()));
191
- return futurePut .join ();
190
+ try {
191
+ CompletableFuture <PutObjectResponse > futurePut = pipeline .putObject (putObjectRequest , AsyncRequestBody .fromInputStream (requestBody .contentStreamProvider ().newStream (), requestBody .optionalContentLength ().orElse (-1L ), Executors .newSingleThreadExecutor ()));
192
+ return futurePut .join ();
193
+ } catch (CompletionException completionException ) {
194
+ throw new S3EncryptionClientException (completionException .getMessage (), completionException .getCause ());
195
+ } catch (Exception exception ) {
196
+ throw new S3EncryptionClientException (exception .getMessage (), exception );
197
+ }
198
+
192
199
}
193
200
194
201
/**
@@ -311,7 +318,7 @@ private CompleteMultipartUploadResponse multipartPutObject(PutObjectRequest requ
311
318
312
319
private <T extends Throwable > T onAbort (UploadObjectObserver observer , T t ) {
313
320
observer .onAbort ();
314
- return t ;
321
+ throw new S3EncryptionClientException ( t . getMessage (), t ) ;
315
322
}
316
323
317
324
/**
@@ -329,15 +336,23 @@ public DeleteObjectResponse deleteObject(DeleteObjectRequest deleteObjectRequest
329
336
DeleteObjectRequest actualRequest = deleteObjectRequest .toBuilder ()
330
337
.overrideConfiguration (API_NAME_INTERCEPTOR )
331
338
.build ();
332
- // Delete the object
333
- DeleteObjectResponse deleteObjectResponse = _wrappedAsyncClient .deleteObject (actualRequest ).join ();
334
- // If Instruction file exists, delete the instruction file as well.
335
- String instructionObjectKey = deleteObjectRequest .key () + INSTRUCTION_FILE_SUFFIX ;
336
- _wrappedAsyncClient .deleteObject (builder -> builder
337
- .overrideConfiguration (API_NAME_INTERCEPTOR )
338
- .bucket (deleteObjectRequest .bucket ())
339
- .key (instructionObjectKey )).join ();
340
- return deleteObjectResponse ;
339
+
340
+ try {
341
+ // Delete the object
342
+ DeleteObjectResponse deleteObjectResponse = _wrappedAsyncClient .deleteObject (actualRequest ).join ();
343
+ // If Instruction file exists, delete the instruction file as well.
344
+ String instructionObjectKey = deleteObjectRequest .key () + INSTRUCTION_FILE_SUFFIX ;
345
+ _wrappedAsyncClient .deleteObject (builder -> builder
346
+ .overrideConfiguration (API_NAME_INTERCEPTOR )
347
+ .bucket (deleteObjectRequest .bucket ())
348
+ .key (instructionObjectKey )).join ();
349
+ // Return original deletion
350
+ return deleteObjectResponse ;
351
+ } catch (CompletionException e ) {
352
+ throw new S3EncryptionClientException (e .getCause ().getMessage (), e .getCause ());
353
+ } catch (Exception e ) {
354
+ throw new S3EncryptionClientException ("Unable to delete object." , e );
355
+ }
341
356
}
342
357
343
358
/**
@@ -355,16 +370,22 @@ public DeleteObjectsResponse deleteObjects(DeleteObjectsRequest deleteObjectsReq
355
370
DeleteObjectsRequest actualRequest = deleteObjectsRequest .toBuilder ()
356
371
.overrideConfiguration (API_NAME_INTERCEPTOR )
357
372
.build ();
358
- // Delete the objects
359
- DeleteObjectsResponse deleteObjectsResponse = _wrappedAsyncClient .deleteObjects (actualRequest ).join ();
360
- // If Instruction files exists, delete the instruction files as well.
361
- List <ObjectIdentifier > deleteObjects = instructionFileKeysToDelete (deleteObjectsRequest );
362
- _wrappedAsyncClient .deleteObjects (DeleteObjectsRequest .builder ()
363
- .overrideConfiguration (API_NAME_INTERCEPTOR )
364
- .bucket (deleteObjectsRequest .bucket ())
365
- .delete (builder -> builder .objects (deleteObjects ))
366
- .build ()).join ();
367
- return deleteObjectsResponse ;
373
+ try {
374
+ // Delete the objects
375
+ DeleteObjectsResponse deleteObjectsResponse = _wrappedAsyncClient .deleteObjects (actualRequest ).join ();
376
+ // If Instruction files exists, delete the instruction files as well.
377
+ List <ObjectIdentifier > deleteObjects = instructionFileKeysToDelete (deleteObjectsRequest );
378
+ _wrappedAsyncClient .deleteObjects (DeleteObjectsRequest .builder ()
379
+ .overrideConfiguration (API_NAME_INTERCEPTOR )
380
+ .bucket (deleteObjectsRequest .bucket ())
381
+ .delete (builder -> builder .objects (deleteObjects ))
382
+ .build ()).join ();
383
+ return deleteObjectsResponse ;
384
+ } catch (CompletionException e ) {
385
+ throw new S3EncryptionClientException (e .getCause ().getMessage (), e .getCause ());
386
+ } catch (Exception e ) {
387
+ throw new S3EncryptionClientException ("Unable to delete objects." , e );
388
+ }
368
389
}
369
390
370
391
/**
@@ -379,7 +400,13 @@ public DeleteObjectsResponse deleteObjects(DeleteObjectsRequest deleteObjectsReq
379
400
*/
380
401
@ Override
381
402
public CreateMultipartUploadResponse createMultipartUpload (CreateMultipartUploadRequest request ) {
382
- return _multipartPipeline .createMultipartUpload (request );
403
+ try {
404
+ return _multipartPipeline .createMultipartUpload (request );
405
+ } catch (CompletionException e ) {
406
+ throw new S3EncryptionClientException (e .getCause ().getMessage (), e .getCause ());
407
+ } catch (Exception e ) {
408
+ throw new S3EncryptionClientException ("Unable to create Multipart upload." , e );
409
+ }
383
410
}
384
411
385
412
/**
@@ -396,7 +423,13 @@ public CreateMultipartUploadResponse createMultipartUpload(CreateMultipartUpload
396
423
@ Override
397
424
public UploadPartResponse uploadPart (UploadPartRequest request , RequestBody requestBody )
398
425
throws AwsServiceException , SdkClientException {
399
- return _multipartPipeline .uploadPart (request , requestBody );
426
+ try {
427
+ return _multipartPipeline .uploadPart (request , requestBody );
428
+ } catch (CompletionException e ) {
429
+ throw new S3EncryptionClientException (e .getCause ().getMessage (), e .getCause ());
430
+ } catch (Exception e ) {
431
+ throw new S3EncryptionClientException ("Unable to upload part." , e );
432
+ }
400
433
}
401
434
402
435
/**
@@ -407,7 +440,13 @@ public UploadPartResponse uploadPart(UploadPartRequest request, RequestBody requ
407
440
@ Override
408
441
public CompleteMultipartUploadResponse completeMultipartUpload (CompleteMultipartUploadRequest request )
409
442
throws AwsServiceException , SdkClientException {
410
- return _multipartPipeline .completeMultipartUpload (request );
443
+ try {
444
+ return _multipartPipeline .completeMultipartUpload (request );
445
+ } catch (CompletionException e ) {
446
+ throw new S3EncryptionClientException (e .getCause ().getMessage (), e .getCause ());
447
+ } catch (Exception e ) {
448
+ throw new S3EncryptionClientException ("Unable to complete Multipart upload." , e );
449
+ }
411
450
}
412
451
413
452
/**
0 commit comments