Ignore non-existing object when deleting (#193)

This commit is contained in:
John Niang
2025-06-11 00:24:19 +08:00
committed by GitHub
parent 19469d0537
commit 42e27da86b

View File

@@ -91,13 +91,16 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
return Mono.just(context); return Mono.just(context);
} }
var properties = S3OsProperties.convertFrom(deleteContext.configMap()); var properties = S3OsProperties.convertFrom(deleteContext.configMap());
return Mono.using(() -> buildS3Client(properties), return Mono.using(
() -> buildS3Client(properties),
client -> Mono.fromCallable( client -> Mono.fromCallable(
() -> client.deleteObject(DeleteObjectRequest.builder() () -> client.deleteObject(DeleteObjectRequest.builder()
.bucket(properties.getBucket()) .bucket(properties.getBucket())
.key(objectKey) .key(objectKey)
.build())).subscribeOn(Schedulers.boundedElastic()), .build())),
S3Client::close) S3Client::close
)
.subscribeOn(Schedulers.boundedElastic())
.doOnNext(response -> { .doOnNext(response -> {
checkResult(response, "delete object"); checkResult(response, "delete object");
log.info("Delete object {} from bucket {} successfully", log.info("Delete object {} from bucket {} successfully",
@@ -105,8 +108,10 @@ public class S3OsAttachmentHandler implements AttachmentHandler {
}) })
.thenReturn(context); .thenReturn(context);
}) })
// ignore when the object does not exist
.onErrorComplete(NoSuchKeyException.class::isInstance)
.onErrorMap(S3ExceptionHandler::map) .onErrorMap(S3ExceptionHandler::map)
.map(DeleteContext::attachment); .thenReturn(deleteContext.attachment());
} }
@Override @Override