Commit 7852ec69 authored by jiaorz's avatar jiaorz

Merge branch 'master-bacground-im' into dev

parents befc49d0 2002770e
...@@ -5,9 +5,11 @@ import com.github.wxiaoqi.security.common.exception.BaseException; ...@@ -5,9 +5,11 @@ import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.exception.auth.ClientTokenException; import com.github.wxiaoqi.security.common.exception.auth.ClientTokenException;
import com.github.wxiaoqi.security.common.exception.auth.UserInvalidException; import com.github.wxiaoqi.security.common.exception.auth.UserInvalidException;
import com.github.wxiaoqi.security.common.exception.auth.UserTokenException; import com.github.wxiaoqi.security.common.exception.auth.UserTokenException;
import com.github.wxiaoqi.security.common.log.Impl.MailServiceImpl;
import com.github.wxiaoqi.security.common.msg.BaseResponse; import com.github.wxiaoqi.security.common.msg.BaseResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -21,7 +23,8 @@ import javax.servlet.http.HttpServletResponse; ...@@ -21,7 +23,8 @@ import javax.servlet.http.HttpServletResponse;
@ResponseBody @ResponseBody
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@Autowired
MailServiceImpl mailService;
@ExceptionHandler(ClientTokenException.class) @ExceptionHandler(ClientTokenException.class)
public BaseResponse clientTokenExceptionHandler(HttpServletResponse response, ClientTokenException ex) { public BaseResponse clientTokenExceptionHandler(HttpServletResponse response, ClientTokenException ex) {
response.setStatus(403); response.setStatus(403);
...@@ -49,6 +52,7 @@ public class GlobalExceptionHandler { ...@@ -49,6 +52,7 @@ public class GlobalExceptionHandler {
if(0 == ex.getStatus()) { if(0 == ex.getStatus()) {
response.setStatus(500); response.setStatus(500);
} }
sendEmail(ex);
return new BaseResponse(ex.getStatus(), ex.getMessage()); return new BaseResponse(ex.getStatus(), ex.getMessage());
} }
...@@ -56,7 +60,16 @@ public class GlobalExceptionHandler { ...@@ -56,7 +60,16 @@ public class GlobalExceptionHandler {
public BaseResponse otherExceptionHandler(HttpServletResponse response, Exception ex) { public BaseResponse otherExceptionHandler(HttpServletResponse response, Exception ex) {
response.setStatus(500); response.setStatus(500);
logger.error(ex.getMessage(),ex); logger.error(ex.getMessage(),ex);
sendEmail(ex);
return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage()); return new BaseResponse(CommonConstants.EX_OTHER_CODE, ex.getMessage());
} }
public void sendEmail(Exception ex) {
try {
logger.info("发送异常邮件,邮件内容:【服务器异常】: {}", ex.getMessage() + ":" + ex);
mailService.sendSimpleMail("jiaoruizhen@126.com", "服务器异常", ex.getMessage() + ":" + ex);
}catch (Exception e) {
logger.error("发送异常邮件失败,异常信息: {}", e);
}
}
} }
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