|
@@ -2,8 +2,10 @@ package com.persagy.fm.common.exception;
|
|
|
|
|
|
import com.persagy.common.enums.ResponseCode;
|
|
import com.persagy.common.enums.ResponseCode;
|
|
import com.persagy.common.exception.BusinessException;
|
|
import com.persagy.common.exception.BusinessException;
|
|
-import com.persagy.fm.common.response.FmResponseUtil;
|
|
|
|
-import com.persagy.fm.common.response.FmResponseMsg;
|
|
|
|
|
|
+import com.persagy.fm.common.response.CommonResult;
|
|
|
|
+import com.persagy.fm.common.utils.ResultHelper;
|
|
|
|
+import com.persagy.security.exception.AESDecryptException;
|
|
|
|
+import com.persagy.security.exception.AESEncryptException;
|
|
import feign.FeignException;
|
|
import feign.FeignException;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
@@ -31,9 +33,18 @@ public class FmExceptionHandler {
|
|
* feign调用异常
|
|
* feign调用异常
|
|
*/
|
|
*/
|
|
@ExceptionHandler({RpcException.class})
|
|
@ExceptionHandler({RpcException.class})
|
|
- public FmResponseMsg handleRpcException(RpcException e) {
|
|
|
|
|
|
+ public CommonResult handleRpcException(RpcException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.C0110.getCode(), e.getMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.C0110.getCode(), e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * token解析失败
|
|
|
|
+ */
|
|
|
|
+ @ExceptionHandler({AESDecryptException.class})
|
|
|
|
+ public CommonResult handleRpcException(AESDecryptException e) {
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0220.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -41,54 +52,54 @@ public class FmExceptionHandler {
|
|
* 空指针异常
|
|
* 空指针异常
|
|
*/
|
|
*/
|
|
@ExceptionHandler(NullPointerException.class)
|
|
@ExceptionHandler(NullPointerException.class)
|
|
- public FmResponseMsg handleBusinessRuntimeException(NullPointerException e) {
|
|
|
|
|
|
+ public CommonResult handleBusinessRuntimeException(NullPointerException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.B0001.getCode(), e.getMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.B0001.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 自定义业务异常
|
|
* 自定义业务异常
|
|
*/
|
|
*/
|
|
@ExceptionHandler(BusinessException.class)
|
|
@ExceptionHandler(BusinessException.class)
|
|
- public FmResponseMsg handleBusinessRuntimeException(BusinessException e) {
|
|
|
|
|
|
+ public CommonResult handleBusinessRuntimeException(BusinessException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(e.getErrorCode(), e.getErrorDesc());
|
|
|
|
|
|
+ return ResultHelper.failure(e.getErrorCode(), e.getErrorDesc());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 入参校验异常
|
|
* 入参校验异常
|
|
*/
|
|
*/
|
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
- public FmResponseMsg handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
|
|
|
|
|
+ public CommonResult handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.A0400.getCode(), e.getBindingResult().getFieldError().getDefaultMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0400.getCode(), e.getBindingResult().getFieldError().getDefaultMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 入参校验异常
|
|
* 入参校验异常
|
|
*/
|
|
*/
|
|
@ExceptionHandler(BindException.class)
|
|
@ExceptionHandler(BindException.class)
|
|
- public FmResponseMsg handleBindException(BindException e) {
|
|
|
|
|
|
+ public CommonResult handleBindException(BindException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.A0400.getCode(), e.getBindingResult().getFieldError().getDefaultMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0400.getCode(), e.getBindingResult().getFieldError().getDefaultMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 参数校验异常,message 为手动抛出时定义的具体异常信息
|
|
* 参数校验异常,message 为手动抛出时定义的具体异常信息
|
|
*/
|
|
*/
|
|
@ExceptionHandler(ValidationException.class)
|
|
@ExceptionHandler(ValidationException.class)
|
|
- public FmResponseMsg handleValidationException(ValidationException e) {
|
|
|
|
|
|
+ public CommonResult handleValidationException(ValidationException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.A0400.getCode(), e.getCause().getMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0400.getCode(), e.getCause().getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 参数校验异常,message 为手动抛出时定义的具体异常信息
|
|
* 参数校验异常,message 为手动抛出时定义的具体异常信息
|
|
*/
|
|
*/
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
- public FmResponseMsg handleIllegalArgumentException(IllegalArgumentException e) {
|
|
|
|
|
|
+ public CommonResult handleIllegalArgumentException(IllegalArgumentException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.A0400.getCode(), e.getMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0400.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -96,9 +107,9 @@ public class FmExceptionHandler {
|
|
*/
|
|
*/
|
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
|
@ExceptionHandler(NoHandlerFoundException.class)
|
|
@ExceptionHandler(NoHandlerFoundException.class)
|
|
- public FmResponseMsg handleNoHandlerFoundException(NoHandlerFoundException e) {
|
|
|
|
|
|
+ public CommonResult handleNoHandlerFoundException(NoHandlerFoundException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.A0422.getCode(), e.getMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0422.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -106,9 +117,9 @@ public class FmExceptionHandler {
|
|
*/
|
|
*/
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
@ExceptionHandler(FeignException.class)
|
|
@ExceptionHandler(FeignException.class)
|
|
- public FmResponseMsg handleFeignException(FeignException e) {
|
|
|
|
|
|
+ public CommonResult handleFeignException(FeignException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.C0110.getCode(), e.getMessage());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.C0110.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -116,9 +127,9 @@ public class FmExceptionHandler {
|
|
*/
|
|
*/
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
@ExceptionHandler(HttpMessageNotReadableException.class)
|
|
@ExceptionHandler(HttpMessageNotReadableException.class)
|
|
- public FmResponseMsg handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
|
|
|
|
|
+ public CommonResult handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.A0402.getCode(), ResponseCode.A0402.getDesc());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.A0402.getCode(), ResponseCode.A0402.getDesc());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -126,8 +137,8 @@ public class FmExceptionHandler {
|
|
*/
|
|
*/
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
@ExceptionHandler(Exception.class)
|
|
@ExceptionHandler(Exception.class)
|
|
- public FmResponseMsg handleException(Exception e) {
|
|
|
|
|
|
+ public CommonResult handleException(Exception e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- return FmResponseUtil.errorMsg(ResponseCode.Z9999.getCode(), ResponseCode.Z9999.getDesc());
|
|
|
|
|
|
+ return ResultHelper.failure(ResponseCode.Z9999.getCode(), ResponseCode.Z9999.getDesc());
|
|
}
|
|
}
|
|
}
|
|
}
|