Skip to content

Commit 3d8b5a0

Browse files
authored
Fix empty files aborting download (#47)
* Make sure to catch RuntimeExceptions as well * Do not fail for empty files * Optimize imports --------- Co-authored-by: KochTobi <[email protected]>
1 parent 2ec049e commit 3d8b5a0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

rest-api/src/main/java/life/qbic/data_download/rest/exceptions/GlobalExceptionHandler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22

33
import static org.slf4j.LoggerFactory.getLogger;
44

5-
import jakarta.servlet.ServletException;
6-
import jakarta.servlet.http.HttpServletRequest;
7-
import jakarta.servlet.http.HttpServletResponse;
8-
import java.io.IOException;
95
import life.qbic.data_download.rest.exceptions.ErrorMessageTranslationService.UserFriendlyErrorMessage;
106
import org.slf4j.Logger;
117
import org.springframework.beans.factory.annotation.Autowired;
128
import org.springframework.http.HttpStatus;
139
import org.springframework.http.HttpStatusCode;
1410
import org.springframework.http.MediaType;
1511
import org.springframework.http.ResponseEntity;
16-
import org.springframework.security.access.AccessDeniedException;
17-
import org.springframework.security.core.Authentication;
18-
import org.springframework.security.core.context.SecurityContextHolder;
19-
import org.springframework.security.web.access.AccessDeniedHandler;
2012
import org.springframework.web.bind.annotation.ControllerAdvice;
2113
import org.springframework.web.bind.annotation.ExceptionHandler;
22-
import org.springframework.web.bind.annotation.ResponseStatus;
2314

2415
/**
2516
* The global exception handler. This exception handler takes effect after authentication and
@@ -59,6 +50,16 @@ public ResponseEntity<String> unknownException(Exception e) {
5950
log.error(e.getMessage(), e);
6051
return ResponseEntity
6152
.status(HttpStatus.INTERNAL_SERVER_ERROR)
53+
.contentType(MediaType.TEXT_PLAIN)
54+
.body("Something went wrong. Please try again later.");
55+
}
56+
57+
@ExceptionHandler(value = RuntimeException.class)
58+
public ResponseEntity<String> unknownException(RuntimeException e) {
59+
log.error(e.getMessage(), e);
60+
return ResponseEntity
61+
.status(HttpStatus.INTERNAL_SERVER_ERROR)
62+
.contentType(MediaType.TEXT_PLAIN)
6263
.body("Something went wrong. Please try again later.");
6364
}
6465

zip/src/main/java/life/qbic/data_download/util/zip/api/FileInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public record FileInfo(String filePath, long fileSize, long expectedCrc, FileTim
1313
if (isNull(fileTimes)) {
1414
fileTimes = FileTimes.unknown();
1515
}
16-
if (fileSize <= 0) {
16+
if (fileSize < 0) {
1717
throw new IllegalArgumentException("File size must be greater than 0");
1818
}
1919
}

0 commit comments

Comments
 (0)