|
|
@@ -3,11 +3,10 @@ package com.style24.scm.support.controller;
|
|
|
import javax.servlet.RequestDispatcher;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
+import org.springframework.boot.web.servlet.error.ErrorController;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
@@ -15,51 +14,48 @@ import com.gagaframework.web.rest.server.GagaResponseStatus;
|
|
|
|
|
|
/**
|
|
|
* Error Controller
|
|
|
+ * Disabling the Whitelabel Error Page
|
|
|
+ * - application.yml 파일에 다음을 추가
|
|
|
+ * server.error.path: /error
|
|
|
+ * server.error.whitelabel.enabled: false
|
|
|
*
|
|
|
* @author gagamel
|
|
|
* @since 2020. 10. 5
|
|
|
*/
|
|
|
@Controller
|
|
|
@Slf4j
|
|
|
-@RequestMapping(value = "/error")
|
|
|
-public class TssErrorController extends TssBaseController {
|
|
|
+public class TssErrorController implements ErrorController {
|
|
|
|
|
|
/**
|
|
|
- * Error
|
|
|
+ * 이 메서드는 스프링 부트 2.3.x부터 deprecated됨.
|
|
|
+ * 이 메서드 대신 custom path를 지정하려면 server.error.path 속성으로 지정해야 한다.
|
|
|
*/
|
|
|
- @GetMapping("/500")
|
|
|
- public ModelAndView error(HttpServletRequest request) throws HttpRequestMethodNotSupportedException {
|
|
|
- ModelAndView mav = new ModelAndView("error/500");
|
|
|
+ @Override
|
|
|
+ public String getErrorPath() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * Error
|
|
|
+ */
|
|
|
+ @GetMapping("/error")
|
|
|
+ public String error(HttpServletRequest request) throws HttpRequestMethodNotSupportedException {
|
|
|
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
|
|
|
|
|
|
if (status != null) {
|
|
|
Integer statusCode = Integer.valueOf(status.toString());
|
|
|
- log.debug("statusCode: {}", statusCode);
|
|
|
+ log.error("Error StatusCode: {}", statusCode);
|
|
|
|
|
|
if (statusCode == GagaResponseStatus.NOT_FOUND.getCode()) {
|
|
|
- mav.addObject("status", GagaResponseStatus.NOT_FOUND.getCode());
|
|
|
- mav.addObject("message", "No mapping found for HTTP request with URI ["
|
|
|
- + String.valueOf(request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI)) + "]");
|
|
|
-
|
|
|
- return mav;
|
|
|
+ return "error/404";
|
|
|
+ } else if (statusCode == GagaResponseStatus.UNAUTHORIZED.getCode()) {
|
|
|
+ return "error/nosession";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- mav.addObject("status", GagaResponseStatus.INTERNAL_SERVER_ERROR.getCode());
|
|
|
- mav.addObject("message", String.valueOf(request.getAttribute(RequestDispatcher.ERROR_MESSAGE)));
|
|
|
-
|
|
|
- return mav;
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/noSession")
|
|
|
- public ModelAndView noSession(HttpServletRequest request) throws HttpRequestMethodNotSupportedException {
|
|
|
- ModelAndView mav = new ModelAndView("error/500");
|
|
|
-
|
|
|
- mav.addObject("status", GagaResponseStatus.UNAUTHORIZED.getCode());
|
|
|
- mav.addObject("message", String.valueOf(request.getAttribute(RequestDispatcher.ERROR_MESSAGE)));
|
|
|
+ log.error("Error Message: {}", request.getAttribute(RequestDispatcher.ERROR_MESSAGE));
|
|
|
|
|
|
- return mav;
|
|
|
+ return "error/500";
|
|
|
}
|
|
|
|
|
|
}
|