国际化定制

pull/6/head
xuxueli 7 years ago
parent 7a362378a4
commit 820b4407d6

@ -11,6 +11,7 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* common exception resolver
@ -24,18 +25,33 @@ public class WebExceptionResolver implements HandlerExceptionResolver {
HttpServletResponse response, Object handler, Exception ex) {
logger.error("WebExceptionResolver:{}", ex);
ModelAndView mv = new ModelAndView();
// if json
boolean isJson = false;
HandlerMethod method = (HandlerMethod)handler;
ResponseBody responseBody = method.getMethodAnnotation(ResponseBody.class);
if (responseBody != null) {
response.setContentType("application/json;charset=UTF-8");
mv.addObject("result", JacksonUtil.writeValueAsString(new ReturnT<String>(500, ex.toString().replaceAll("\n", "<br/>"))));
mv.setViewName("/common/common.result");
isJson = true;
}
// error result
ReturnT<String> errorResult = new ReturnT<String>(ReturnT.FAIL_CODE, ex.toString().replaceAll("\n", "<br/>"));
// response
ModelAndView mv = new ModelAndView();
if (isJson) {
try {
response.setContentType("application/json;charset=utf-8");
response.getWriter().print(JacksonUtil.writeValueAsString(errorResult));
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return mv;
} else {
mv.addObject("exceptionMsg", ex.toString().replaceAll("\n", "<br/>"));
mv.addObject("exceptionMsg", errorResult.getMsg());
mv.setViewName("/common/common.exception");
return mv;
}
return mv;
}
}

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title> (500)</title>
<title>Error</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
@ -21,8 +21,9 @@
<body>
<div class="dialog">
<h1></h1>
<p>访</p>
<h1>System Error</h1>
<p>Oops! Page not found.</p>
<a href="javascript:window.location.href='${request.contextPath}/'">Back</a>
</div>
</body>

@ -25,7 +25,7 @@
<h4>${I18n.admin_name_full}</h4>
<br>
<p>
<a target="_blank" href="https://github.com/xuxueli/xxl-job">github</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a target="_blank" href="https://github.com/xuxueli/xxl-job">Github</a>&nbsp;&nbsp;&nbsp;&nbsp;
<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>
<br><br>
<a target="_blank" href="http://www.xuxueli.com/xxl-job/">${I18n.job_help_document}</a>

Loading…
Cancel
Save