异常打印2
This commit is contained in:
parent
1dfc594a29
commit
3cb39035ed
|
|
@ -4,10 +4,8 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||||
import cn.dev33.satoken.exception.NotPermissionException;
|
import cn.dev33.satoken.exception.NotPermissionException;
|
||||||
import cn.dev33.satoken.exception.NotRoleException;
|
import cn.dev33.satoken.exception.NotRoleException;
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
import cn.hutool.core.io.resource.NoResourceException;
|
|
||||||
import com.czg.resp.CzgRespCode;
|
import com.czg.resp.CzgRespCode;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
|
@ -142,24 +140,24 @@ public class CzgControllerAdvice {
|
||||||
return CzgResult.failure(CzgRespCode.RECORD_EXISTED);
|
return CzgResult.failure(CzgRespCode.RECORD_EXISTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
// @ResponseBody
|
||||||
@ExceptionHandler(value = Exception.class)
|
// @ExceptionHandler(value = Exception.class)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
// @ResponseStatus(HttpStatus.OK)
|
||||||
public CzgResult<Object> errorHandler(Exception ex) {
|
// public CzgResult<Object> errorHandler(Exception ex) {
|
||||||
Throwable rootCause = ex;
|
// Throwable rootCause = ex;
|
||||||
while (rootCause.getCause() != null) {
|
// while (rootCause.getCause() != null) {
|
||||||
rootCause = rootCause.getCause();
|
// rootCause = rootCause.getCause();
|
||||||
if (rootCause instanceof CzgException) {
|
// if (rootCause instanceof CzgException) {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// 处理自定义异常
|
// // 处理自定义异常
|
||||||
if (rootCause instanceof CzgException czgException) {
|
// if (rootCause instanceof CzgException czgException) {
|
||||||
return CzgResult.failure(czgException.getCode(), czgException.getMessage());
|
// return CzgResult.failure(czgException.getCode(), czgException.getMessage());
|
||||||
}
|
// }
|
||||||
setErrorLog(ex);
|
// setErrorLog(ex);
|
||||||
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
|
// return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void setErrorLog(Exception ex) {
|
private void setErrorLog(Exception ex) {
|
||||||
// log.error(ex.getMessage());
|
// log.error(ex.getMessage());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue