|
@@ -1,5 +1,6 @@
|
|
package com.persagy.dmp.common.handler;
|
|
package com.persagy.dmp.common.handler;
|
|
|
|
|
|
|
|
+import cn.hutool.core.exceptions.ExceptionUtil;
|
|
import com.persagy.dmp.common.constant.ResponseCode;
|
|
import com.persagy.dmp.common.constant.ResponseCode;
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
|
|
|
|
|
import javax.validation.ValidationException;
|
|
import javax.validation.ValidationException;
|
|
|
|
+import java.sql.SQLException;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @description: 通用异常处理类
|
|
* @description: 通用异常处理类
|
|
@@ -31,7 +33,7 @@ public class CommonExceptionHandler {
|
|
@ExceptionHandler(NullPointerException.class)
|
|
@ExceptionHandler(NullPointerException.class)
|
|
public CommonResult handleBusinessRuntimeException(NullPointerException e) {
|
|
public CommonResult handleBusinessRuntimeException(NullPointerException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return ResultHelper.failure(ResponseCode.B0001.getCode(), e.getMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.B0001.getCode(), ExceptionUtil.getRootCauseMessage(e));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -44,6 +46,17 @@ public class CommonExceptionHandler {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * SQL异常
|
|
|
|
+ * @param e
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ExceptionHandler(SQLException.class)
|
|
|
|
+ public CommonResult handleSQLException(SQLException e) {
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0400.getCode(), e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 入参校验异常
|
|
* 入参校验异常
|
|
*/
|
|
*/
|
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
@@ -106,6 +119,7 @@ public class CommonExceptionHandler {
|
|
@ExceptionHandler(Exception.class)
|
|
@ExceptionHandler(Exception.class)
|
|
public CommonResult handleException(Exception e) {
|
|
public CommonResult handleException(Exception e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return ResultHelper.failure(ResponseCode.Z9999.getCode(), ResponseCode.Z9999.getDesc());
|
|
|
|
|
|
+ // 20210819 返回实际的异常信息
|
|
|
|
+ return ResultHelper.failure(ResponseCode.Z9999.getCode(), ExceptionUtil.getRootCauseMessage(e));
|
|
}
|
|
}
|
|
}
|
|
}
|