Merge pull request #229 from bsinno/Fix_wrong_multipart_exception_message_in_response

Return last throwable in response
This commit is contained in:
Michael Hirsch
2016-07-04 08:27:06 +02:00
committed by GitHub

View File

@@ -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<Throwable> 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());