参数错误
This commit is contained in:
@@ -14,6 +14,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
|
|||||||
import org.springframework.validation.ObjectError;
|
import org.springframework.validation.ObjectError;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||||
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;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
@@ -63,14 +64,14 @@ public class CzgControllerAdvice {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(value = NotPermissionException.class)
|
@ExceptionHandler(value = NotPermissionException.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public CzgResult<Object> notPermissionErrorHandler(NotPermissionException ex) {
|
public CzgResult<Object> notPermissionErrorHandler() {
|
||||||
return CzgResult.failure(CzgRespCode.UN_PERMISSION);
|
return CzgResult.failure(CzgRespCode.UN_PERMISSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(value = NotRoleException.class)
|
@ExceptionHandler(value = NotRoleException.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public CzgResult<Object> notRoleErrorHandler(NotRoleException ex) {
|
public CzgResult<Object> notRoleErrorHandler() {
|
||||||
return CzgResult.failure(CzgRespCode.UN_ROLE);
|
return CzgResult.failure(CzgRespCode.UN_ROLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +119,12 @@ public class CzgControllerAdvice {
|
|||||||
return CzgResult.failure(701, "订单已过期,请重新下单");
|
return CzgResult.failure(701, "订单已过期,请重新下单");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||||
|
public CzgResult<Object> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex) {
|
||||||
|
log.error("传参错误", ex);
|
||||||
|
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统繁忙,请稍后再试");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理Hutool的断言抛出异常
|
* 处理Hutool的断言抛出异常
|
||||||
*/
|
*/
|
||||||
@@ -156,7 +163,7 @@ public class CzgControllerAdvice {
|
|||||||
public CzgResult<Object> errorHandler(Exception ex) {
|
public CzgResult<Object> errorHandler(Exception ex) {
|
||||||
// setErrorLog(ex);
|
// setErrorLog(ex);
|
||||||
// 3. 处理未捕获的异常(系统异常,隐藏敏感信息)
|
// 3. 处理未捕获的异常(系统异常,隐藏敏感信息)
|
||||||
log.error("系统未处理异常", ex); // 替换原有 setErrorLog,使用日志框架
|
log.error("系统未处理异常", ex);
|
||||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统繁忙,请稍后再试");
|
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统繁忙,请稍后再试");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user