From 46ce3b632a4df64b7195b29a1e93f0e0eacb8760 Mon Sep 17 00:00:00 2001 From: Sebastian Firsching <56029682+sebastian-firsching@users.noreply.github.com> Date: Tue, 17 Mar 2020 08:04:11 +0100 Subject: [PATCH] Add spring exception handler for FileStreamingFailedException (#943) Signed-off-by: Sebastian Firsching --- .../exception/ResponseExceptionHandler.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java index e5448b36d..d1c5f3f04 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java +++ b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java @@ -21,6 +21,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; +import org.eclipse.hawkbit.rest.util.FileStreamingFailedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -117,6 +118,28 @@ public class ResponseExceptionHandler { return new ResponseEntity<>(response, responseStatus); } + /** + * Method for handling exception of type + * {@link FileStreamingFailedException} which is thrown in case the + * streaming of a file failed due to an internal server error. As the + * streaming of the file has already begun, no JSON response but only the + * ResponseStatus 500 is returned. Called by the Spring-Framework for + * exception handling. + * + * @param request + * the Http request + * @param ex + * the exception which occurred + * @return the entity to be responded containing the response status 500 + */ + @ExceptionHandler(FileStreamingFailedException.class) + public ResponseEntity handleFileStreamingFailedException(final HttpServletRequest request, + final Exception ex) { + logRequest(request, ex); + LOG.warn("File streaming failed: {}", ex.getMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + /** * Method for handling exception of type HttpMessageNotReadableException and * MethodArgumentNotValidException which are thrown in case the request body