diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java index 13e214c45..02a48ef78 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java @@ -9,11 +9,12 @@ package org.eclipse.hawkbit.rest.exception; import java.util.EnumMap; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import org.apache.tomcat.util.http.fileupload.FileUploadException; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.exception.SpServerRtException; import org.eclipse.hawkbit.repository.exception.MultiPartFileUploadException; @@ -27,6 +28,8 @@ import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.multipart.MultipartException; +import com.google.common.collect.Iterables; + /** * General controller advice for exception handling. */ @@ -135,13 +138,8 @@ public class ResponseExceptionHandler { logRequest(request, ex); - Throwable responseCause = ex; - - final Throwable searchForCause = searchForCause(ex, FileUploadException.class); - if (searchForCause != null) { - responseCause = searchForCause; - } - + final List throwables = ExceptionUtils.getThrowableList(ex); + final Throwable responseCause = Iterables.getLast(throwables); final ExceptionInfo response = createExceptionInfo(new MultiPartFileUploadException(responseCause)); return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); } @@ -150,19 +148,6 @@ public class ResponseExceptionHandler { LOG.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL()); } - private static Throwable searchForCause(final Throwable t, final Class lookFor) { - if (t == null || t.getCause() == null) { - return null; - } - - final Throwable cause = t.getCause(); - - if (cause.getClass().equals(lookFor)) { - return cause; - } - return searchForCause(cause, lookFor); - } - private ExceptionInfo createExceptionInfo(final Exception ex) { final ExceptionInfo response = new ExceptionInfo(); response.setMessage(ex.getMessage());