diff --git a/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java b/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java index c8fc40a..830c07b 100644 --- a/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/example/demo/aop/handler/GlobalExceptionHandler.java @@ -4,6 +4,8 @@ package com.example.demo.aop.handler; import java.util.logging.Level; import java.util.logging.Logger; +import jakarta.servlet.http.HttpSession; + import org.springframework.http.HttpStatus; import org.springframework.ui.Model; import org.springframework.web.HttpRequestMethodNotSupportedException; @@ -37,25 +39,31 @@ public class GlobalExceptionHandler { } @ExceptionHandler(HttpRequestMethodNotSupportedException.class) - public String handleBadRequestException(Model model, Exception e) { + public String handleBadRequestException(Model model, Exception e, HttpSession session) { model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST); model.addAttribute("status", HttpStatus.BAD_REQUEST.value()); e.printStackTrace(); LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e); + + System.out.println("session invalidated"); + session.invalidate(); return "error"; } @ExceptionHandler(Exception.class) - public String AllException(Model model, Exception e) { + public String AllException(Model model, Exception e, HttpSession session) { model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST); e.printStackTrace(); LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e); + System.out.println("session invalidated"); + session.invalidate(); + return "error"; } }