Commit a9367c09 authored by 周健威's avatar 周健威

去除邮件发送通知

parent 86fb39f2
...@@ -40,15 +40,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -40,15 +40,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Value("${spring.application.name}") @Value("${spring.application.name}")
private String applicationName; private String applicationName;
@Value("${email.log.account}")
private String emailLogAccount;
@Value("${email.log.title}")
private String emailLogTitle;
@Value("${email.log.host}")
private String emailLogHost;
/** /**
* 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的 * 在controller里面内容执行之前,校验一些参数不匹配啊,Get post方法不对啊之类的
*/ */
...@@ -94,43 +85,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { ...@@ -94,43 +85,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
response.setStatus(500); response.setStatus(500);
logger.error(ex.getMessage(),ex); logger.error(ex.getMessage(),ex);
Throwable cause = ex.getCause(); Throwable cause = ex.getCause();
if(cause != null && cause.toString().contains("Exception") && !cause.toString().contains("UserTokenException")) {
StringWriter stringWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stringWriter));
logger.error(cause.getMessage(), ex);
Map<String, String> map = new HashMap<>();
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try {
HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
logger.error(e.getMessage());
}
return new BaseResponse(5000, "Server exception: " + ex.getMessage());
}
Map<String, String> map = new HashMap<>();
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" + ex.toString() + ":" + ex.getMessage());
try {
HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception e) {
logger.error(e.getMessage());
}
return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage()); return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage());
} }
public String initCommonLogPrePart() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();//获取request
StringBuilder stringBuilder = new StringBuilder();
//request 获得头部
stringBuilder.append(request.getHeader("app"));
LocalDateTime startTime= LocalDateTime.now();//开始时间
stringBuilder.append("》》" +startTime.toString());
stringBuilder.append("》》" +request.getServletPath());
stringBuilder.append("》》" +applicationName + ":" + request.getServletPath());
return stringBuilder.toString();
}
} }
...@@ -26,15 +26,6 @@ public class PlatformExceptionHandler { ...@@ -26,15 +26,6 @@ public class PlatformExceptionHandler {
@Value("${spring.application.name}") @Value("${spring.application.name}")
private String applicationName; private String applicationName;
@Value("${email.log.account}")
private String emailLogAccount;
@Value("${email.log.title}")
private String emailLogTitle;
@Value("${email.log.host}")
private String emailLogHost;
@ExceptionHandler(value = {BaseException.class}) @ExceptionHandler(value = {BaseException.class})
public BaseResponse baseExceptionHandler(Exception e) { public BaseResponse baseExceptionHandler(Exception e) {
if (e instanceof BaseException){ if (e instanceof BaseException){
...@@ -47,33 +38,6 @@ public class PlatformExceptionHandler { ...@@ -47,33 +38,6 @@ public class PlatformExceptionHandler {
//服务器异常 //服务器异常
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public ObjectRestResponse<?> exceptionHandler(Exception e){ public ObjectRestResponse<?> exceptionHandler(Exception e){
Throwable cause = e.getCause();
if(cause != null && cause.toString().contains("Exception") && !cause.toString().contains("UserTokenException")) {
StringWriter stringWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stringWriter));
log.error(cause.getMessage(), e);
Map<String, String> map = new HashMap<>();
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" +stringWriter.toString());
try {
HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) {
log.error(ex.getMessage());
}
return assembleResult(ObjectRestResponse.createFailedResult(5000, "服务器开小差了,请稍后重试!"), "Server exception: " + e.getMessage());
}
log.error("Server exception: ", e);
Map<String, String> map = new HashMap<>();
map.put("toUser", emailLogAccount);
map.put("subject", emailLogTitle);
map.put("content", initCommonLogPrePart()+ ":" + e.toString() + ":" + e.getMessage());
try {
HttpUtils.doPost(emailLogHost,"/api/universal/mail/app/unauth/send", map);
} catch (Exception ex) {
log.error(ex.getMessage());
}
return assembleResult(ObjectRestResponse.createFailedResult(5000, "服务器开小差了,请稍后重试!"), "Server exception: " + e.getMessage()); return assembleResult(ObjectRestResponse.createFailedResult(5000, "服务器开小差了,请稍后重试!"), "Server exception: " + e.getMessage());
} }
...@@ -87,17 +51,4 @@ public class PlatformExceptionHandler { ...@@ -87,17 +51,4 @@ public class PlatformExceptionHandler {
} }
public String initCommonLogPrePart() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();//获取request
StringBuilder stringBuilder = new StringBuilder();
//request 获得头部
LocalDateTime startTime= LocalDateTime.now();//开始时间
stringBuilder.append("》》" +startTime.toString());
stringBuilder.append("》》" +request.getServletPath());
stringBuilder.append("》》" +applicationName + ":" + request.getServletPath());
return stringBuilder.toString();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment