Skip to content
Snippets Groups Projects
Commit 15ed6f79 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Improve Exception handling

parent 189670cd
1 merge request!89Foundation for development of version 3.0
...@@ -25,6 +25,7 @@ import de.thm.arsnova.exceptions.NotImplementedException; ...@@ -25,6 +25,7 @@ import de.thm.arsnova.exceptions.NotImplementedException;
import de.thm.arsnova.exceptions.PayloadTooLargeException; import de.thm.arsnova.exceptions.PayloadTooLargeException;
import de.thm.arsnova.exceptions.PreconditionFailedException; import de.thm.arsnova.exceptions.PreconditionFailedException;
import de.thm.arsnova.exceptions.UnauthorizedException; import de.thm.arsnova.exceptions.UnauthorizedException;
import org.ektorp.DocumentNotFoundException;
import org.slf4j.event.Level; import org.slf4j.event.Level;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
...@@ -33,12 +34,14 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken; ...@@ -33,12 +34,14 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.NoHandlerFoundException; import org.springframework.web.servlet.NoHandlerFoundException;
import javax.naming.OperationNotSupportedException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Map; import java.util.Map;
...@@ -109,7 +112,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl ...@@ -109,7 +112,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
return handleException(e, Level.DEBUG); return handleException(e, Level.DEBUG);
} }
@ExceptionHandler(BadRequestException.class) @ExceptionHandler({BadRequestException.class, HttpRequestMethodNotSupportedException.class})
@ResponseBody @ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public Map<String, Object> handleBadRequestException(final Exception e, final HttpServletRequest request) { public Map<String, Object> handleBadRequestException(final Exception e, final HttpServletRequest request) {
...@@ -123,7 +126,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl ...@@ -123,7 +126,7 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
return handleException(e, Level.DEBUG); return handleException(e, Level.DEBUG);
} }
@ExceptionHandler(NotImplementedException.class) @ExceptionHandler({NotImplementedException.class, OperationNotSupportedException.class})
@ResponseBody @ResponseBody
@ResponseStatus(HttpStatus.NOT_IMPLEMENTED) @ResponseStatus(HttpStatus.NOT_IMPLEMENTED)
public Map<String, Object> handleNotImplementedException(final Exception e, final HttpServletRequest request) { public Map<String, Object> handleNotImplementedException(final Exception e, final HttpServletRequest request) {
...@@ -143,4 +146,12 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl ...@@ -143,4 +146,12 @@ public class ControllerExceptionHandler extends AbstractControllerExceptionHandl
public Map<String, Object> handleHttpMessageNotReadableException(final Exception e, final HttpServletRequest request) { public Map<String, Object> handleHttpMessageNotReadableException(final Exception e, final HttpServletRequest request) {
return handleException(e, Level.DEBUG); return handleException(e, Level.DEBUG);
} }
/* FIXME: Wrap persistance Exceptions - do not handle persistance Exceptions at the controller layer */
@ExceptionHandler(DocumentNotFoundException.class)
@ResponseBody
@ResponseStatus(HttpStatus.NOT_FOUND)
public Map<String, Object> handleDocumentNotFoundException(final Exception e, final HttpServletRequest request) {
return handleException(e, Level.TRACE);
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment