|
|
@@ -8,7 +8,6 @@ import com.mrxu.framework.common.util.BusinessException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
-import org.springframework.validation.FieldError;
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
@@ -37,38 +36,25 @@ public class FeignProviderExceptionHandler {
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
public Object handleException(Exception e) {
|
|
|
+ if(e instanceof BusinessException) {
|
|
|
+ BusinessException error = (BusinessException)e;
|
|
|
+ log.warn(e.getMessage());
|
|
|
+ return rendError(true,new BaseCode(error.getCode(),error.getMsg()));
|
|
|
+ }
|
|
|
+ else if(e instanceof MethodArgumentNotValidException) {
|
|
|
+ MethodArgumentNotValidException error = (MethodArgumentNotValidException)e;
|
|
|
+ BindingResult result = error.getBindingResult();
|
|
|
+ log.warn("请求参数错误:{}",result.getFieldError().getDefaultMessage());
|
|
|
+ return rendError(true,BaseCode.ERR_PARAMS_VALID);
|
|
|
+ }
|
|
|
+ else if(e instanceof MissingServletRequestParameterException) {
|
|
|
+ log.warn("请求缺少参数:{}",e.getMessage());
|
|
|
+ return rendError(true,BaseCode.ERR_PARAMS_MISS);
|
|
|
+ }
|
|
|
log.error("系统错误:{}",e.getMessage(), e);
|
|
|
return rendError(false,BaseCode.ERROR);
|
|
|
}
|
|
|
|
|
|
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- @ExceptionHandler(BusinessException.class)
|
|
|
- public Object handleLogicalException(BusinessException e) {
|
|
|
- log.warn(e.getMessage());
|
|
|
- return rendError(true,new BaseCode(e.getCode(),e.getMsg()));
|
|
|
- }
|
|
|
-
|
|
|
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- @ExceptionHandler(MethodArgumentNotValidException.class)
|
|
|
- public Object handleValidException(MethodArgumentNotValidException e) {
|
|
|
- BindingResult result = e.getBindingResult();
|
|
|
- FieldError error = result.getFieldError();
|
|
|
- log.warn("请求参数错误:{}",error.getDefaultMessage());
|
|
|
- return rendError(true,BaseCode.ERR_PARAMS_VALID);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 缺少必要参数
|
|
|
- * @param e
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- @ExceptionHandler(MissingServletRequestParameterException.class)
|
|
|
- public Object handleValidException(MissingServletRequestParameterException e) {
|
|
|
- log.warn("请求缺少参数:{}",e.getMessage());
|
|
|
- return rendError(true,BaseCode.ERR_PARAMS_MISS);
|
|
|
- }
|
|
|
-
|
|
|
public Object rendError(boolean isBusinessException,BaseCode code) {
|
|
|
HttpServletRequest request = ServletUtils.getRequest();
|
|
|
FeignProviderException exception = new FeignProviderException(isBusinessException,code);
|