Jelajahi Sumber

ajax로 호출 시 alert 메시지를 노출하고 그 외는 500 에러 페이지로 노출

gagamel 4 tahun lalu
induk
melakukan
6b8d0d47bc

+ 21 - 16
src/main/java/com/style24/core/support/controller/TscBaseController.java

@@ -5,6 +5,8 @@ import java.sql.SQLException;
 import java.sql.SQLRecoverableException;
 import java.util.Set;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.ConstraintViolation;
 import javax.validation.Validation;
 import javax.validation.Validator;
@@ -22,16 +24,19 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.InitBinder;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
 import com.fasterxml.jackson.databind.JsonMappingException;
-import com.gagaframework.web.rest.exception.GagaRestException;
-import com.gagaframework.web.rest.server.GagaResponse;
-import com.gagaframework.web.rest.server.GagaResponseStatus;
 import com.style24.core.biz.thirdparty.KollusApi;
 import com.style24.core.support.message.TscMessageByLocale;
 
 import lombok.extern.slf4j.Slf4j;
 
+import com.gagaframework.web.rest.exception.GagaRestException;
+import com.gagaframework.web.rest.server.GagaResponse;
+import com.gagaframework.web.rest.server.GagaResponseStatus;
+
 /**
  * Controller Advice
  * 
@@ -129,19 +134,19 @@ public class TscBaseController {
 		}
 
 		// Ajax 호출인지 여부를 체크. 2021.11.16. gagamel
-		// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
-		// String reqWith = request.getHeader("x-requested-with");
-		//
-		// if (StringUtils.isBlank(reqWith) || !"XMLHttpRequest".equals(reqWith)) {
-		// 	HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
-		//
-		// 	try {
-		// 		// 에러 페이지로 forwarding
-		// 		request.getRequestDispatcher("/error").forward(request, response);
-		// 	} catch (Exception e) {
-		// 		// Do nothing
-		// 	}
-		// }
+		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+		String reqWith = request.getHeader("x-requested-with");
+		
+		if (StringUtils.isBlank(reqWith) || !"XMLHttpRequest".equals(reqWith)) {
+			HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
+		
+			try {
+				// 에러 페이지로 forwarding
+				request.getRequestDispatcher("/error").forward(request, response);
+			} catch (Exception e) {
+				// Do nothing
+			}
+		}
 		// Ajax 호출인지 여부를 체크. 2021.11.16. gagamel
 
 		if (throwable instanceof SQLException || throwable instanceof BindingException