|
|
@@ -2,7 +2,7 @@ package cn.qinys.platform.base.exceptions;
|
|
|
|
|
|
|
|
|
|
|
|
-import cn.qinys.platform.base.response.UnifyResponse;
|
|
|
+import cn.qinys.platform.base.response.Result;
|
|
|
import cn.qinys.platform.base.response.ResultCodeEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
@@ -37,9 +37,9 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = Exception.class)
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- public UnifyResponse<String> defaultErrorHandler(Exception ex) {
|
|
|
+ public Result<String> defaultErrorHandler(Exception ex) {
|
|
|
log.error("全局异常: [{}]", ex.getMessage(), ex);
|
|
|
- return new UnifyResponse<String>(ResultCodeEnum.INTERNAL_SERVER_ERROR).setData(ex.getMessage());
|
|
|
+ return new Result<String>(ResultCodeEnum.INTERNAL_SERVER_ERROR).setData(ex.getMessage());
|
|
|
// 网络安全中心要求发生异常时不能泄漏代码和数据库的信息,直接返回ex.getMessage()可能会泄露.
|
|
|
//return new Result<String>(ResultCodeEnum.INTERNAL_SERVER_ERROR).setData("");
|
|
|
}
|
|
|
@@ -47,9 +47,9 @@ public class GlobalDefaultExceptionHandler {
|
|
|
|
|
|
@ExceptionHandler(value = AccessDeniedException.class)
|
|
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
|
|
- public UnifyResponse<String> accessDeniedHandler(Exception ex) {
|
|
|
+ public Result<String> accessDeniedHandler(Exception ex) {
|
|
|
log.error("401:该账号无权限: [{}]", ex.getMessage());
|
|
|
- return new UnifyResponse<>(ResultCodeEnum.UNAUTHORIZED);
|
|
|
+ return new Result<>(ResultCodeEnum.UNAUTHORIZED);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -61,12 +61,12 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- public UnifyResponse<String> validationErrorHandler(MethodArgumentNotValidException ex) {
|
|
|
+ public Result<String> validationErrorHandler(MethodArgumentNotValidException ex) {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
ex.getBindingResult().getAllErrors().forEach(error -> sb.append(error.getDefaultMessage()).append(","));
|
|
|
log.error("验证未通过 ==> [{}], 字段 ==> [{}]", ex.getMessage(), sb.toString());
|
|
|
//return new Result<String>(ResultCodeEnum.VALIDATE_NOT_ACCESS).setMsg(sb.toString());
|
|
|
- return new UnifyResponse<>(400, sb.toString());
|
|
|
+ return new Result<>(400, sb.toString());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -77,9 +77,9 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = MissingServletRequestParameterException.class)
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- public UnifyResponse<String> missingServletRequestParameterErrorHandler(MissingServletRequestParameterException ex) {
|
|
|
+ public Result<String> missingServletRequestParameterErrorHandler(MissingServletRequestParameterException ex) {
|
|
|
log.error("缺少请求参数:[{}]", ex.getMessage());
|
|
|
- return new UnifyResponse<String>(ResultCodeEnum.MISSING_REQUEST_PARAMETER).setData(ex.getMessage());
|
|
|
+ return new Result<String>(ResultCodeEnum.MISSING_REQUEST_PARAMETER).setData(ex.getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -90,9 +90,9 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = BindException.class)
|
|
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- public UnifyResponse<String> badRequestErrorHandler(BindException ex) {
|
|
|
+ public Result<String> badRequestErrorHandler(BindException ex) {
|
|
|
log.error("请求参数类型错误:[{}]", ex.getMessage());
|
|
|
- return new UnifyResponse<String>(ResultCodeEnum.BAD_REQUEST).setData(ex.getMessage());
|
|
|
+ return new Result<String>(ResultCodeEnum.BAD_REQUEST).setData(ex.getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -103,9 +103,9 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = SQLException.class)
|
|
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- public UnifyResponse<String> databaseErrorHandler(SQLException ex) {
|
|
|
+ public Result<String> databaseErrorHandler(SQLException ex) {
|
|
|
log.error("数据库操作错误:[{}]", ex.getMessage());
|
|
|
- return new UnifyResponse<String>(ResultCodeEnum.DATABASE_ERROR).setData(ex.getMessage());
|
|
|
+ return new Result<String>(ResultCodeEnum.DATABASE_ERROR).setData(ex.getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -116,9 +116,9 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = ConnectException.class)
|
|
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
- public UnifyResponse<String> connect(ConnectException ex) {
|
|
|
+ public Result<String> connect(ConnectException ex) {
|
|
|
log.error("网络连接失败:[{}]", ex.getMessage());
|
|
|
- return new UnifyResponse<String>(ResultCodeEnum.CONNECTION_ERROR).setData(ex.getMessage());
|
|
|
+ return new Result<String>(ResultCodeEnum.CONNECTION_ERROR).setData(ex.getMessage());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -129,9 +129,9 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = BizException.class)
|
|
|
@ResponseStatus(value = HttpStatus.OK)
|
|
|
- public UnifyResponse<String> bizException(BizException ex) {
|
|
|
+ public Result<String> bizException(BizException ex) {
|
|
|
log.info("业务异常:[{}]=={}", ex.getMsg(), ex.getData());
|
|
|
- return new UnifyResponse<>(400, ex.getMsg(), ex.getMsg());
|
|
|
+ return new Result<>(400, ex.getMsg(), ex.getMsg());
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -144,8 +144,8 @@ public class GlobalDefaultExceptionHandler {
|
|
|
*/
|
|
|
@ExceptionHandler(value = HttpClientErrorException.class)
|
|
|
@ResponseStatus(value = HttpStatus.FORBIDDEN)
|
|
|
- public UnifyResponse<String> badRequestException(HttpClientErrorException ex) {
|
|
|
- return new UnifyResponse<>(403, ex.getMessage());
|
|
|
+ public Result<String> badRequestException(HttpClientErrorException ex) {
|
|
|
+ return new Result<>(403, ex.getMessage());
|
|
|
}
|
|
|
|
|
|
}
|