分布式事务异常判断

This commit is contained in:
jieyuu 2024-08-26 15:05:06 +08:00
parent e65a801a62
commit 8b16ce48de
3 changed files with 30 additions and 27 deletions

View File

@ -1,28 +1,28 @@
package net.jieyuu.exception; package net.jieyuu.exception;
//import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
//import net.jieyuu.utils.JsonData; import net.jieyuu.utils.JsonData;
//import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
//
//@ControllerAdvice @ControllerAdvice
//@Slf4j @Slf4j
//public class CustomExceptionHandle { public class CustomExceptionHandle {
//
// @ExceptionHandler(value = Exception.class) @ExceptionHandler(value = Exception.class)
// @ResponseBody @ResponseBody
// public JsonData Handle(Exception e) { public JsonData Handle(Exception e) {
//
// if (e instanceof BizException) { if (e instanceof BizException) {
// BizException bizException = (BizException) e; BizException bizException = (BizException) e;
// log.info("[业务异常]{}", e); log.info("[业务异常]{}", e);
// return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg()); return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg());
//
// } else { } else {
// log.info("[系统异常]{}", e); log.info("[系统异常]{}", e);
// return JsonData.buildError("全局异常,未知错误"); return JsonData.buildError("全局异常,未知错误");
// } }
//
// } }
//} }

View File

@ -140,6 +140,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
request.setName(userDO.getName()); request.setName(userDO.getName());
request.setUserId(userDO.getId()); request.setUserId(userDO.getId());
JsonData jsonData = couponFeignService.addNewUserCoupon(request); JsonData jsonData = couponFeignService.addNewUserCoupon(request);
if (jsonData.getCode() != 0) {
throw new RuntimeException("发放优惠券异常");
}
log.info("发放新用户注册优惠券: {},结果:{}", request.toString(), jsonData.toString()); log.info("发放新用户注册优惠券: {},结果:{}", request.toString(), jsonData.toString());
} }