初始化提交
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.czg.exception;
|
||||
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import com.czg.resp.CzgRespCode;
|
||||
import com.czg.resp.CzgResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -39,6 +40,30 @@ public class CzgControllerAdvice {
|
||||
return CzgResult.failure(CzgRespCode.PARAM_ERROR.getCode(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自定义异常
|
||||
*/
|
||||
@ExceptionHandler(value = {CzgException.class, IllegalArgumentException.class})
|
||||
public CzgResult handleCzgException(CzgException ex) {
|
||||
return CzgResult.failure(ex.getCode(), ex.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理Hutool的断言抛出异常
|
||||
*/
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public CzgResult handleAssertException(IllegalArgumentException ex) {
|
||||
return CzgResult.failure(CzgRespCode.PARAM_ERROR.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理Hutool的校验工具类抛出异常
|
||||
*/
|
||||
@ExceptionHandler(ValidateException.class)
|
||||
public CzgResult handleHutoolValidateException(ValidateException ex) {
|
||||
return CzgResult.failure(CzgRespCode.PARAM_ERROR.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
private void setErrorLog(Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user