Browse Source

ErrorRender.getErrorRender(int errorCode) 中通过 errorCode 获取 errorView
参数的代码转移至 ErrorRender.render(),因为需要在 render() 当时判断是否为 json 请求

James 3 years ago
parent
commit
c2c35b1424
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/main/java/com/jfinal/render/ErrorRender.java

+ 8 - 0
src/main/java/com/jfinal/render/ErrorRender.java

@@ -115,6 +115,14 @@ public class ErrorRender extends Render {
 		String ct = request.getContentType();
 		String ct = request.getContentType();
 		boolean isJsonContentType = ct != null && ct.indexOf("json") != -1;
 		boolean isJsonContentType = ct != null && ct.indexOf("json") != -1;
 		
 		
+		// 支持 me.setErrorView(xxx.html) 配置
+		// 注意:针对 json 的 setErrorJsonContent(...) 直接覆盖掉了默认值,走后面的 response.getOutputStream().write(...) 即何
+		if (viewOrJson == null) {
+		    if (! isJsonContentType) {
+		        viewOrJson = getErrorView(getErrorCode());
+		    }
+		}
+		
 		// render with viewOrJson
 		// render with viewOrJson
 		if (viewOrJson != null) {
 		if (viewOrJson != null) {
 			if (isJsonContentType) {
 			if (isJsonContentType) {