Skip to content

Commit 42e27da

Browse files
authored
Ignore non-existing object when deleting (#193)
1 parent 19469d0 commit 42e27da

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/run/halo/s3os/S3OsAttachmentHandler.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,27 @@ public Mono<Attachment> delete(DeleteContext deleteContext) {
9191
return Mono.just(context);
9292
}
9393
var properties = S3OsProperties.convertFrom(deleteContext.configMap());
94-
return Mono.using(() -> buildS3Client(properties),
94+
return Mono.using(
95+
() -> buildS3Client(properties),
9596
client -> Mono.fromCallable(
9697
() -> client.deleteObject(DeleteObjectRequest.builder()
9798
.bucket(properties.getBucket())
9899
.key(objectKey)
99-
.build())).subscribeOn(Schedulers.boundedElastic()),
100-
S3Client::close)
100+
.build())),
101+
S3Client::close
102+
)
103+
.subscribeOn(Schedulers.boundedElastic())
101104
.doOnNext(response -> {
102105
checkResult(response, "delete object");
103106
log.info("Delete object {} from bucket {} successfully",
104107
objectKey, properties.getBucket());
105108
})
106109
.thenReturn(context);
107110
})
111+
// ignore when the object does not exist
112+
.onErrorComplete(NoSuchKeyException.class::isInstance)
108113
.onErrorMap(S3ExceptionHandler::map)
109-
.map(DeleteContext::attachment);
114+
.thenReturn(deleteContext.attachment());
110115
}
111116

112117
@Override

0 commit comments

Comments
 (0)