Commit c242477a authored by shiyu's avatar shiyu

GlobalExceptionHandler返回数据格式修改

parent 3324cb73
package com.wwdz.ch.core.config;
import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.type.Result;
import org.hibernate.validator.internal.engine.path.PathImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -29,28 +31,28 @@ public class GlobalExceptionHandler {
@ResponseBody
public Object badArgumentHandler(IllegalArgumentException e) {
logger.error("error {}", e);
return ResponseUtil.badArgumentValue();
return Result.failed(ResultCode.PARAM_VALUE_ERROR);
}
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseBody
public Object badArgumentHandler(MethodArgumentTypeMismatchException e) {
logger.error("error {}", e);
return ResponseUtil.badArgumentValue();
return Result.failed(ResultCode.PARAM_VALUE_ERROR);
}
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseBody
public Object badArgumentHandler(MissingServletRequestParameterException e) {
logger.error("error {}", e);
return ResponseUtil.badArgumentValue();
return Result.failed(ResultCode.PARAM_VALUE_ERROR);
}
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseBody
public Object badArgumentHandler(HttpMessageNotReadableException e) {
logger.error("error {}", e);
return ResponseUtil.badArgumentValue();
return Result.failed(ResultCode.PARAM_VALUE_ERROR);
}
@ExceptionHandler(ValidationException.class)
......@@ -62,16 +64,16 @@ public class GlobalExceptionHandler {
Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
for (ConstraintViolation<?> item : violations) {
String message = ((PathImpl) item.getPropertyPath()).getLeafNode().getName() + item.getMessage();
return ResponseUtil.fail(402, message);
return Result.failed(402, message);
}
}
return ResponseUtil.badArgumentValue();
return Result.failed(ResultCode.PARAM_VALUE_ERROR);
}
@ExceptionHandler(Exception.class)
@ResponseBody
public Object seriousHandler(Exception e) {
logger.error("error {}", e);
return ResponseUtil.serious();
return Result.failed(ResultCode.AUCTION_ITEM_LIMIT);
}
}
......@@ -9,6 +9,7 @@ public enum ResultCode {
SUCCESS(0, "成功"),
UNLOGIN(401, "未登录"),
PARAM_VALUE_ERROR(402, "参数值不对"),
FAILED(4000, "操作失败"),
UNKNOWN_USER(4001, "请先登录"),
INVALID_FILE(4002, "文件类型不正确"),
......
......@@ -48,9 +48,7 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
"/wx/specialPerformance/sendMsg", "/wx/specialPerformance/sendMsgTest", "/wx/groupPurchase/systemAddRecord","/wx/officialAccount/**",
"/wx/supplierItem/**","/wx/specialPerformance/**","/wx/groupPurchase/**","/wx/disposableSubscribeRecord/**", "/wx/auctionRecord/findList",
"/wx/selfPage/countIntroduceAmount",
"/wx/exchange/**"
"/wx/exchange/findExchangeItem"
//下列路径上线注释
/* ,"/wx/specialPerformance/**"
, "/wx/supplierItem/**", "/wx/shareRecord/**", "/wx/distributionOrder/**", "/wx/selfPage/**", "/wx/auctionRecord/**",
......
package com.wwdz.ch.wx.interceptor;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.domain.Switch;
import com.wwdz.ch.db.domain.User;
......
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