File tree 1 file changed +11
-0
lines changed
app/src/main/java/it/chalmers/gamma/adapter/primary/web
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 6
6
import jakarta .servlet .http .HttpServletRequest ;
7
7
import jakarta .servlet .http .HttpServletResponse ;
8
8
import java .io .IOException ;
9
+
10
+ import org .slf4j .Logger ;
11
+ import org .slf4j .LoggerFactory ;
9
12
import org .springframework .http .HttpStatus ;
10
13
import org .springframework .security .access .AccessDeniedException ;
11
14
import org .springframework .web .bind .annotation .ControllerAdvice ;
18
21
@ ControllerAdvice
19
22
public class ThymeleafAdvice {
20
23
24
+ private static final Logger LOGGER = LoggerFactory .getLogger (ThymeleafAdvice .class );
25
+
21
26
@ ModelAttribute ("isAdmin" )
22
27
public boolean isAdmin () {
23
28
if (AuthenticationExtractor .getAuthentication ()
@@ -28,6 +33,12 @@ public boolean isAdmin() {
28
33
}
29
34
}
30
35
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
+
31
42
@ ExceptionHandler (AccessGuard .AccessDeniedException .class )
32
43
public ModelAndView handleAccessDeniedException (HttpServletRequest request ) {
33
44
boolean htmxRequest = "true" .equals (request .getHeader ("HX-Request" ));
You can’t perform that action at this time.
0 commit comments