File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
app/src/main/java/it/chalmers/gamma/adapter/primary/web Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 66import jakarta .servlet .http .HttpServletRequest ;
77import jakarta .servlet .http .HttpServletResponse ;
88import java .io .IOException ;
9+
10+ import org .slf4j .Logger ;
11+ import org .slf4j .LoggerFactory ;
912import org .springframework .http .HttpStatus ;
1013import org .springframework .security .access .AccessDeniedException ;
1114import org .springframework .web .bind .annotation .ControllerAdvice ;
1821@ ControllerAdvice
1922public class ThymeleafAdvice {
2023
24+ private static final Logger LOGGER = LoggerFactory .getLogger (ThymeleafAdvice .class );
25+
2126 @ ModelAttribute ("isAdmin" )
2227 public boolean isAdmin () {
2328 if (AuthenticationExtractor .getAuthentication ()
@@ -28,6 +33,12 @@ public boolean isAdmin() {
2833 }
2934 }
3035
36+ @ ExceptionHandler (IllegalArgumentException .class )
37+ public ModelAndView handleIllegalArgumentException (HttpServletRequest request , IllegalArgumentException ex ) {
38+ LOGGER .error ("Caught IllegalArgumentException. This shouldn't happen as validators should catch these issues:" , ex );
39+ return new ModelAndView ("redirect:/error" );
40+ }
41+
3142 @ ExceptionHandler (AccessGuard .AccessDeniedException .class )
3243 public ModelAndView handleAccessDeniedException (HttpServletRequest request ) {
3344 boolean htmxRequest = "true" .equals (request .getHeader ("HX-Request" ));
You can’t perform that action at this time.
0 commit comments