paascloud/paascloud-master · error · OmcBizException

OMC10031007

OMC10031007

Error message

OMC10031007

What it means

ErrorCodeEnum.OMC10031007 ('no default address exists', 不存在默认地址) is thrown by setDefaultAddress when selectDefaultAddressByUserId finds no current default shipping address for the user, so there is nothing to compare against or unset before promoting the new address.

Solutions

  1. Initialize a default: if no default exists, directly set the given addressId as default instead of throwing (or run a one-time UPDATE to seed defaults)
  2. Backfill data: UPDATE omc_shipping SET default_address = 1 WHERE id = (oldest address per user) for affected users
  3. Verify loginAuthDto.getUserId() is the correct user and that user actually owns addresses

Example fix

// before
OmcShipping omcShipping = omcShippingMapper.selectDefaultAddressByUserId(userId);
if (PublicUtil.isEmpty(omcShipping)) {
    throw new OmcBizException(ErrorCodeEnum.OMC10031007);
}
// after
OmcShipping omcShipping = omcShippingMapper.selectDefaultAddressByUserId(userId);
if (PublicUtil.isEmpty(omcShipping)) {
    return doSetDefault(addressId, loginAuthDto); // no prior default: just set it
}
Defensive patterns

Strategy: fallback

Validate before calling

OmcShipping current = omcShippingMapper.selectDefaultAddressByUserId(userId);
boolean hasDefault = current != null;
// if !hasDefault, skip comparison and set the target address directly

Type guard

boolean hasDefaultAddress(Long userId) {
    return omcShippingMapper.selectDefaultAddressByUserId(userId) != null;
}

Try / catch

try {
    shippingService.setDefaultAddress(addressId, loginAuthDto);
} catch (OmcBizException e) {
    if (e.getCode() == 10031007) {
        shippingService.setDefault(addressId, 1, loginAuthDto); // seed first default
    } else throw e;
}

Prevention

When it happens

Trigger: Calling setDefaultAddress(addressId, loginAuthDto) for a user who has never had a default address (first address, default flag never set, or the previous default was deleted).

Common situations: New accounts with freshly added addresses, data migrations that dropped the default flag, users deleting their default address, or querying the wrong user id from the login token.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcShippingServiceImpl.java:111

		return new PageInfo<>(omcShippingList);
	}

	@Override
	public List<OmcShipping> selectByUserId(Long userId) {
		Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
		return omcShippingMapper.selectByUserId(userId);
	}

	@Transactional(rollbackFor = Exception.class)
	@Override
	public int setDefaultAddress(LoginAuthDto loginAuthDto, Long addressId) {
		Long userId = loginAuthDto.getUserId();
		Preconditions.checkArgument(addressId != null, "地址ID不能为空");

		// 1. 查找当前默认地址
		OmcShipping omcShipping = omcShippingMapper.selectDefaultAddressByUserId(userId);
		if (PublicUtil.isEmpty(omcShipping)) {
			throw new OmcBizException(ErrorCodeEnum.OMC10031007);
		}
		// 2. 判断默认地址和当前传入地址是否相同
		if (addressId.equals(omcShipping.getId())) {
			logger.info("所选地址和当前用户默认地址相同 userId={}, addressId={}", userId, addressId);
			return 1;
		}
		// 3. 相同不处理不相同把当前改为非默认, 把当前地址改为默认地址
		setDefault(loginAuthDto, addressId, OmcApiConstant.Shipping.DEFAULT);
		setDefault(loginAuthDto, omcShipping.getId(), OmcApiConstant.Shipping.NOT_DEFAULT);

		return 1;
	}

	private void setDefault(LoginAuthDto loginAuthDto, Long addressId, int isDefault) {
		int result;
		OmcShipping updateNotDefault = new OmcShipping();
		updateNotDefault.setDefaultAddress(isDefault);
		updateNotDefault.setUpdateInfo(loginAuthDto);

View on GitHub (pinned to 781281a950)