From 273b87194c9864273e7996277f15f28930afa58a Mon Sep 17 00:00:00 2001 From: Patrick Magee Date: Thu, 25 Apr 2024 10:38:24 -0400 Subject: [PATCH] [#187456042] fixed 404 not being handled when trying to delete file that does not exist --- .../test/java/com/dnastack/wes/service/WesE2ETest.java | 2 +- .../java/com/dnastack/wes/files/RunFileDeletion.java | 3 ++- src/main/java/com/dnastack/wes/files/RunFileService.java | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/e2e-tests/src/test/java/com/dnastack/wes/service/WesE2ETest.java b/e2e-tests/src/test/java/com/dnastack/wes/service/WesE2ETest.java index 66d9398..04bd826 100644 --- a/e2e-tests/src/test/java/com/dnastack/wes/service/WesE2ETest.java +++ b/e2e-tests/src/test/java/com/dnastack/wes/service/WesE2ETest.java @@ -596,7 +596,7 @@ public void deleteRunFilesReturnsNonEmptyCollection(String runId) { .assertThat() .statusCode(200) .body("deletions.size()", greaterThan(0)) - .body("deletions.every { it.path != null && it.file_type == 'SECONDARY' && it.state == 'DELETED' }", equalTo(true)); + .body("deletions.every { it.path != null && it.file_type == 'SECONDARY' && (it.state == 'DELETED' || it.state == 'NOT_FOUND') }", equalTo(true)); //@formatter:on } diff --git a/src/main/java/com/dnastack/wes/files/RunFileDeletion.java b/src/main/java/com/dnastack/wes/files/RunFileDeletion.java index 30eba0e..10b03f9 100644 --- a/src/main/java/com/dnastack/wes/files/RunFileDeletion.java +++ b/src/main/java/com/dnastack/wes/files/RunFileDeletion.java @@ -9,7 +9,8 @@ public record RunFileDeletion(@JsonUnwrapped RunFile runFile, DeletionState stat public enum DeletionState { DELETED, ASYNC, - FAILED + FAILED, + NOT_FOUND } } diff --git a/src/main/java/com/dnastack/wes/files/RunFileService.java b/src/main/java/com/dnastack/wes/files/RunFileService.java index 24650a6..c075729 100644 --- a/src/main/java/com/dnastack/wes/files/RunFileService.java +++ b/src/main/java/com/dnastack/wes/files/RunFileService.java @@ -116,10 +116,13 @@ public RunFileDeletion deleteRunFileAsync(RunFile runFile) { public RunFileDeletion deleteRunFile(RunFile runFile) { try { storageClient.deleteFile(runFile.getPath()); - log.info("Deleting file '{}'", runFile.getPath()); + log.debug("Deleting file '{}'", runFile.getPath()); return new RunFileDeletion(runFile, RunFileDeletion.DeletionState.DELETED, null); - } catch (IOException e) { - log.error("Encountered exception while deleting file '%s': '%s'".formatted(runFile.getPath(), e.getMessage()), e); + } catch (NotFoundException e){ + log.debug("File '{}' was not found, skipping deletion", runFile.getPath()); + return new RunFileDeletion(runFile, RunFileDeletion.DeletionState.NOT_FOUND, ErrorResponse.builder().errorCode(404).msg(e.getMessage()).build()); + } catch (Exception e) { + log.debug("Encountered exception while deleting file '%s': '%s'".formatted(runFile.getPath(), e.getMessage()), e); return new RunFileDeletion(runFile, RunFileDeletion.DeletionState.FAILED, ErrorResponse.builder().errorCode(400).msg(e.getMessage()).build()); } }