xuxueli před 8 roky
rodič
revize
820b4407d6

+ 23 - 7
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/resolver/WebExceptionResolver.java Zobrazit soubor

@@ -11,6 +11,7 @@ import org.springframework.web.servlet.ModelAndView;
11 11
 
12 12
 import javax.servlet.http.HttpServletRequest;
13 13
 import javax.servlet.http.HttpServletResponse;
14
+import java.io.IOException;
14 15
 
15 16
 /**
16 17
  * common exception resolver
@@ -23,19 +24,34 @@ public class WebExceptionResolver implements HandlerExceptionResolver {
23 24
 	public ModelAndView resolveException(HttpServletRequest request,
24 25
 			HttpServletResponse response, Object handler, Exception ex) {
25 26
 		logger.error("WebExceptionResolver:{}", ex);
26
-		
27
-		ModelAndView mv = new ModelAndView();
27
+
28
+		// if json
29
+		boolean isJson = false;
28 30
 		HandlerMethod method = (HandlerMethod)handler;
29 31
 		ResponseBody responseBody = method.getMethodAnnotation(ResponseBody.class);
30 32
 		if (responseBody != null) {
31
-			response.setContentType("application/json;charset=UTF-8");
32
-			mv.addObject("result", JacksonUtil.writeValueAsString(new ReturnT<String>(500, ex.toString().replaceAll("\n", "<br/>"))));
33
-			mv.setViewName("/common/common.result");
33
+			isJson = true;
34
+		}
35
+
36
+		// error result
37
+		ReturnT<String> errorResult = new ReturnT<String>(ReturnT.FAIL_CODE, ex.toString().replaceAll("\n", "<br/>"));
38
+
39
+		// response
40
+		ModelAndView mv = new ModelAndView();
41
+		if (isJson) {
42
+			try {
43
+				response.setContentType("application/json;charset=utf-8");
44
+				response.getWriter().print(JacksonUtil.writeValueAsString(errorResult));
45
+			} catch (IOException e) {
46
+				logger.error(e.getMessage(), e);
47
+			}
48
+			return mv;
34 49
 		} else {
35
-			mv.addObject("exceptionMsg", ex.toString().replaceAll("\n", "<br/>"));	
50
+
51
+			mv.addObject("exceptionMsg", errorResult.getMsg());
36 52
 			mv.setViewName("/common/common.exception");
53
+			return mv;
37 54
 		}
38
-		return mv;
39 55
 	}
40 56
 	
41 57
 }

+ 4 - 3
xxl-job-admin/src/main/webapp/500.html Zobrazit soubor

@@ -2,7 +2,7 @@
2 2
 <html>
3 3
 <head>
4 4
 	<meta charset="UTF-8">
5
-	<title>应用程序异常 (500)</title> 
5
+	<title>Error</title>
6 6
     <style type="text/css"> 
7 7
         body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
8 8
         div.dialog {
@@ -21,8 +21,9 @@
21 21
 <body> 
22 22
 
23 23
 	<div class="dialog"> 
24
-	    <h1>应用程序异常</h1> 
25
-	    <p>抱歉!您访问的页面出现异常,请稍后重试或联系管理员。</p> 
24
+	    <h1>System Error</h1>
25
+	    <p>Oops! Page not found.</p>
26
+		<a href="javascript:window.location.href='${request.contextPath}/'">Back</a>
26 27
 	</div>
27 28
 
28 29
 </body>

+ 0 - 1
xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.result.ftl Zobrazit soubor

@@ -1 +0,0 @@
1
-${result?if_exists}

+ 1 - 1
xxl-job-admin/src/main/webapp/WEB-INF/template/help.ftl Zobrazit soubor

@@ -25,7 +25,7 @@
25 25
 				<h4>${I18n.admin_name_full}</h4>
26 26
 				<br>
27 27
 				<p>
28
-					<a target="_blank" href="https://github.com/xuxueli/xxl-job">github</a>&nbsp;&nbsp;&nbsp;&nbsp;
28
+					<a target="_blank" href="https://github.com/xuxueli/xxl-job">Github</a>&nbsp;&nbsp;&nbsp;&nbsp;
29 29
 					<iframe src="https://ghbtns.com/github-btn.html?user=xuxueli&repo=xxl-job&type=star&count=true" frameborder="0" scrolling="0" width="170px" height="20px" style="margin-bottom:-5px;"></iframe> 
30 30
 					<br><br>
31 31
                     <a target="_blank" href="http://www.xuxueli.com/xxl-job/">${I18n.job_help_document}</a>