paascloud/paascloud-master · error · MdcBizException

MDC10021022

MDC10021022

Error message

MDC10021022

What it means

MdcProductServiceImpl.updateProductStockById calls mdcProductFeignApi.updateProductStockById(productDto); if the returned wrapper is a failed response (wrapper.error()), it throws MdcBizException with ErrorCodeEnum MDC10021022 (message '更新商品库存失败' — stock update failed), formatted with the product id. The Feign call itself succeeded, but the OMC-side stock update operation reported failure (e.g. affected rows 0).

Solutions

  1. Verify the product id exists (mdc_product table) and is active before calling updateProductStockById
  2. Inspect the upstream OMC update SQL/mapper — a 0-row update (stock already at limit or record missing) is the usual root cause; add row-count logging
  3. Handle concurrency with a proper optimistic lock or atomic 'UPDATE ... SET stock = stock - ? WHERE stock >= ?' and retry on conflict
  4. Catch MdcBizException in the caller and roll back the order/transaction, returning a 'stock update failed' user message

Example fix

// before: unchecked failure leaves order inconsistent
mdcProductService.updateProductStockById(productDto);
// after: guard and rollback
try {
    mdcProductService.updateProductStockById(productDto);
} catch (MdcBizException e) {
    log.error("stock update failed for product {}", productDto.getId(), e);
    throw new OrderBizException(ErrorCodeEnum.OMC10031004);
}
Defensive patterns

Strategy: try-catch

Validate before calling

Preconditions.checkArgument(productDto.getId() != null, "product id required");
// optionally verify existence first:
MdcProduct product = mdcProductMapper.selectById(productDto.getId());
Preconditions.checkState(product != null, "product not found: " + productDto.getId());

Try / catch

try {
  mdcProductService.updateProductStockById(productDto);
} catch (MdcBizException e) {
  if (ErrorCodeEnum.MDC10021022.getCode().equals(e.getCode())) {
    // stock update failed upstream — compensate/rollback order
    orderService.rollback(orderNo);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling updateProductStockById with a productDto whose id does not match an existing product, or whose stock delta cannot be applied (e.g. decrementing stock below what the upstream SQL allows, or optimistic-lock/row-count check failing in the OMC provider), so the Feign response wrapper carries error=true.

Common situations: Ordering/checkout flow decrementing stock for a product deleted or deactivated in another service; concurrent stock updates causing the conditional UPDATE to match 0 rows; stale product id from a cached cart; Feign misconfiguration pointing at a wrong environment where the product doesn't exist.

Related errors


AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10). Data as JSON: /api/errors/ac36422147b127f7. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/MdcProductServiceImpl.java:82

		if (wrapper == null) {
			throw new MdcBizException(ErrorCodeEnum.GL99990002);
		}
		if (wrapper.error()) {
			throw new MdcBizException(ErrorCodeEnum.MDC10021004, productId);
		}
		return wrapper.getResult();
	}

	@Override
	public int updateProductStockById(ProductDto productDto) {
		Preconditions.checkArgument(productDto.getId() != null, ErrorCodeEnum.MDC10021021.msg());
		Wrapper<Integer> wrapper = mdcProductFeignApi.updateProductStockById(productDto);
		if (wrapper == null) {
			throw new MdcBizException(ErrorCodeEnum.GL99990002);
		}
		if (wrapper.error()) {
			throw new MdcBizException(ErrorCodeEnum.MDC10021022, productDto.getId());
		}
		return wrapper.getResult();
	}

	@Override
	public String getMainImage(final Long productId) {
		Wrapper<String> wrapper = mdcProductFeignApi.getMainImage(productId);
		if (wrapper == null) {
			throw new MdcBizException(ErrorCodeEnum.GL99990002);
		}
		return wrapper.getResult();
	}
}

View on GitHub (pinned to 781281a950)