|
|
@@ -1,96 +0,0 @@
|
|
|
-package com.style24.front.support.controller;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import javax.servlet.RequestDispatcher;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
-import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
|
|
|
-import org.springframework.boot.web.error.ErrorAttributeOptions;
|
|
|
-import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.mobile.device.Device;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.servlet.ModelAndView;
|
|
|
-
|
|
|
-import com.style24.front.support.util.ViewUtils;
|
|
|
-
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-
|
|
|
-/**
|
|
|
- * Custom Error Controller
|
|
|
- * Disabling the Whitelabel Error Page
|
|
|
- * - application.yml 파일에 다음을 추가
|
|
|
- * server.error.path='/error'
|
|
|
- * server.error.whitelabel.enabled=false
|
|
|
- *
|
|
|
- * @author gagamel
|
|
|
- * @since 2020. 9. 11
|
|
|
- */
|
|
|
-@Controller
|
|
|
-@RequestMapping("${server.error.path:${error.path:/error}}")
|
|
|
-@Slf4j
|
|
|
-public class TsfCustomErrorController extends AbstractErrorController {
|
|
|
-
|
|
|
- public TsfCustomErrorController(ErrorAttributes errorAttributes) {
|
|
|
- super(errorAttributes);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getErrorPath() {
|
|
|
- return this.getErrorPath();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * HTML로 응답을 주는 경우의 처리
|
|
|
- * @param request - HttpServletRequest
|
|
|
- * @param response - HttpServletResponse
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- @RequestMapping(produces = MediaType.TEXT_HTML_VALUE)
|
|
|
- public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response, Device device) throws IOException {
|
|
|
- HttpStatus status = this.getStatus(request);
|
|
|
- log.error("status.value(): {}", status.value());
|
|
|
-
|
|
|
- Map<String, Object> model = this.getErrorAttributes(request, ErrorAttributeOptions.defaults());
|
|
|
-
|
|
|
- response.setStatus(status.value());
|
|
|
- ModelAndView mav = this.resolveErrorView(request, response, status, model);
|
|
|
-
|
|
|
- if (status.value() == HttpStatus.NOT_FOUND.value()) {
|
|
|
- return (mav != null) ? mav : new ModelAndView(ViewUtils.getDeviceViewName("error/404"), model);
|
|
|
- }
|
|
|
-
|
|
|
- Object oExceptionType = request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE);
|
|
|
- if (oExceptionType != null) {
|
|
|
- String exceptionType = oExceptionType.toString();
|
|
|
- log.error("ERROR_EXCEPTION_TYPE: {}", exceptionType);
|
|
|
-
|
|
|
- // Thymeleaf의 HTML 파일을 못 찾는 에러는 "org.thymeleaf.exceptions.TemplateInputException"임.
|
|
|
- if (exceptionType.endsWith("org.thymeleaf.exceptions.TemplateInputException")) {
|
|
|
- return (mav != null) ? mav : new ModelAndView(ViewUtils.getDeviceViewName("error/404"), model);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return (mav != null) ? mav : new ModelAndView(ViewUtils.getDeviceViewName("error/500"), model);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * HTML 외의 응답이 필요한 경우의 처리
|
|
|
- * @param request - HttpServletRequest
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping
|
|
|
- public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
|
|
|
- Map<String, Object> body = this.getErrorAttributes(request, ErrorAttributeOptions.defaults());
|
|
|
- HttpStatus status = this.getStatus(request);
|
|
|
- return new ResponseEntity<>(body, status);
|
|
|
- }
|
|
|
-
|
|
|
-}
|