[EDIT] 二次実装に伴う定数の追加と、AOPのクラスも定数クラスを参照するよう編集しました。
This commit is contained in:
@@ -10,6 +10,7 @@ import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
|
||||
import com.example.demo.exception.NoSessionException;
|
||||
|
||||
|
||||
@@ -32,7 +33,7 @@ public class SessionCheckAspect {
|
||||
public void checkSession() {
|
||||
HttpSession session = request.getSession(false);
|
||||
|
||||
if (session == null || session.getAttribute("loginUser") == null) {
|
||||
if (session == null || session.getAttribute(SessionKeyword.LOGIN_USER) == null) {
|
||||
throw new NoSessionException("不正なログインです");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
|
||||
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
|
||||
import com.example.demo.exception.NoSessionException;
|
||||
|
||||
@ControllerAdvice
|
||||
@@ -30,18 +32,18 @@ public class GlobalExceptionHandler {
|
||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||
|
||||
model.addAttribute(
|
||||
"errorMessage",
|
||||
PageReturnAttributeKeyword.ERROR_MESSAGE,
|
||||
"システムエラーが発生しました。"
|
||||
+ "初めからやり直してください。");
|
||||
|
||||
return "redirect:/login";
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
|
||||
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public String handleBadRequestException(Model model, Exception e, HttpSession session) {
|
||||
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
|
||||
model.addAttribute(PageReturnAttributeKeyword.ERROR, SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||
model.addAttribute(PageReturnAttributeKeyword.STATUS, HttpStatus.BAD_REQUEST.value());
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -50,7 +52,7 @@ public class GlobalExceptionHandler {
|
||||
System.out.println("session invalidated");
|
||||
session.invalidate();
|
||||
|
||||
return "error";
|
||||
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@@ -60,6 +62,6 @@ public class GlobalExceptionHandler {
|
||||
|
||||
System.out.println("session invalidated exception");
|
||||
session.invalidate();
|
||||
return "error";
|
||||
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ public class GoalController {
|
||||
|
||||
int currentAmount = goalService.getCurrentAmount(userId);
|
||||
|
||||
model.addAttribute("currentAmount", currentAmount);
|
||||
model.addAttribute(PageReturnAttributeKeyword.CURRENT_AMOUNT, currentAmount);
|
||||
|
||||
return TransitionTargetPageNameKeyword.GOAL_CREATE_HTML;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ public class PageReturnAttributeKeyword {
|
||||
|
||||
public static final String ERROR_MESSAGE = "errorMessage";
|
||||
public static final String MESSAGE = "message";
|
||||
|
||||
public static final String ERROR = "error";
|
||||
public static final String STATUS = "status";
|
||||
|
||||
public static final String QUESTION_LIST = "questionList";
|
||||
public static final String USER_FORM = "userForm";
|
||||
|
||||
Reference in New Issue
Block a user