mirror of https://gitee.com/maxjhandsome/pig
♻️ Refactoring code.增加业务校验异常的全局统一处理
This commit is contained in:
parent
ab0e0fb8c1
commit
6ad2447333
|
@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.core.SpringSecurityMessageSource;
|
import org.springframework.security.core.SpringSecurityMessageSource;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.validation.FieldError;
|
import org.springframework.validation.FieldError;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
@ -60,6 +61,23 @@ public class GlobalBizExceptionHandler {
|
||||||
return R.failed(e.getLocalizedMessage());
|
return R.failed(e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理业务校验过程中碰到的非法参数异常 该异常基本由{@link org.springframework.util.Assert}抛出
|
||||||
|
* @see Assert#hasLength(String, String)
|
||||||
|
* @see Assert#hasText(String, String)
|
||||||
|
* @see Assert#isTrue(boolean, String)
|
||||||
|
* @see Assert#isNull(Object, String)
|
||||||
|
* @see Assert#notNull(Object, String)
|
||||||
|
* @param exception 参数校验异常
|
||||||
|
* @return API返回结果对象包装后的错误输出结果
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(IllegalArgumentException.class)
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public R handleIllegalArgumentException(IllegalArgumentException exception) {
|
||||||
|
log.error("非法参数,ex = {}", exception.getMessage(), exception);
|
||||||
|
return R.failed(exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AccessDeniedException
|
* AccessDeniedException
|
||||||
* @param e the e
|
* @param e the e
|
||||||
|
|
Loading…
Reference in New Issue