diff --git a/app/src/main/java/it/chalmers/gamma/adapter/primary/web/ThymeleafAdvice.java b/app/src/main/java/it/chalmers/gamma/adapter/primary/web/ThymeleafAdvice.java index 828908d46..e4912730d 100644 --- a/app/src/main/java/it/chalmers/gamma/adapter/primary/web/ThymeleafAdvice.java +++ b/app/src/main/java/it/chalmers/gamma/adapter/primary/web/ThymeleafAdvice.java @@ -6,6 +6,9 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.security.access.AccessDeniedException; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -18,6 +21,8 @@ @ControllerAdvice public class ThymeleafAdvice { + private static final Logger LOGGER = LoggerFactory.getLogger(ThymeleafAdvice.class); + @ModelAttribute("isAdmin") public boolean isAdmin() { if (AuthenticationExtractor.getAuthentication() @@ -28,6 +33,12 @@ public boolean isAdmin() { } } +@ExceptionHandler(IllegalArgumentException.class) +public ModelAndView handleIllegalArgumentException(HttpServletRequest request, IllegalArgumentException ex) { + LOGGER.error("Caught IllegalArgumentException. This shouldn't happen as validators should catch these issues:", ex); + return new ModelAndView("redirect:/error"); + } + @ExceptionHandler(AccessGuard.AccessDeniedException.class) public ModelAndView handleAccessDeniedException(HttpServletRequest request) { boolean htmxRequest = "true".equals(request.getHeader("HX-Request"));