修改Response 的date响应字段
This commit is contained in:
@@ -26,12 +26,11 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@ControllerAdvice
|
||||
public class ExceptionHandle {
|
||||
public static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
|
||||
@Autowired
|
||||
MailService mailService;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
public static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeModel;
|
||||
|
||||
@@ -41,27 +40,27 @@ public class ExceptionHandle {
|
||||
//自定义错误
|
||||
if (e instanceof MyException) {
|
||||
logger.debug("返回了自定义的exception,[code={},msg={}]", ((MyException) e).getCode(), e.getMessage());
|
||||
return new Response(((MyException) e).getCode(), e.getMessage(), null, System.currentTimeMillis());
|
||||
return new Response(((MyException) e).getCode(), e.getMessage(), null);
|
||||
}
|
||||
//请求路径不支持该方法
|
||||
if (e instanceof HttpRequestMethodNotSupportedException) {
|
||||
logger.debug("遇到请求路径与请求方法不匹配的请求,[msg={},path:{},method:{}]", e.getMessage(),request.getRequestURL(),request.getMethod());
|
||||
return new Response(ResponseEnum.ERROR.getCode(), e.getMessage(), null, System.currentTimeMillis());
|
||||
logger.debug("遇到请求路径与请求方法不匹配的请求,[msg={},path:{},method:{}]", e.getMessage(), request.getRequestURL(), request.getMethod());
|
||||
return new Response(ResponseEnum.ERROR.getCode(), e.getMessage(), null);
|
||||
}
|
||||
//数据输入类型不匹配
|
||||
if (e instanceof MethodArgumentTypeMismatchException) {
|
||||
logger.debug("输入类型不匹配,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改后再访问", null, System.currentTimeMillis());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改后再访问", null);
|
||||
}
|
||||
//数据验证失败
|
||||
if (e instanceof BindException) {
|
||||
logger.debug("数据验证失败,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改", null, System.currentTimeMillis());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改", null);
|
||||
}
|
||||
//数据输入不完整
|
||||
if (e instanceof MissingServletRequestParameterException) {
|
||||
logger.debug("数据输入不完整,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入不完整,请检查", null, System.currentTimeMillis());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入不完整,请检查", null);
|
||||
}
|
||||
|
||||
// 发送错误信息到邮箱
|
||||
@@ -70,7 +69,7 @@ public class ExceptionHandle {
|
||||
sendMessage(e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
return new Response(ResponseEnum.ERROR.getCode(), "服务器出现错误,已记录", null, System.currentTimeMillis());
|
||||
return new Response(ResponseEnum.ERROR.getCode(), "服务器出现错误,已记录", null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user