iflytek/astron-agent · error · BusinessException

SPACE_USER_ADD_FAILED

SPACE_USER_ADD_FAILED

Error message

SPACE_USER_ADD_FAILED

What it means

SPACE_USER_ADD_FAILED is thrown when approving an enterprise space application succeeds up to updating the apply record, but adding the applicant as a space MEMBER via spaceUserService.addSpaceUser returns false. The approval cannot complete because the membership insert/update failed.

Solutions

  1. Check whether the user is already a member of the space (idempotent handling)
  2. Verify the space and applicant still exist before approving
  3. Inspect spaceUserService logs/DB errors for the underlying write failure
  4. Make addSpaceUser idempotent so re-approval doesn't fail on existing membership

Example fix

// before
if (!spaceUserService.addSpaceUser(spaceId, uid, SpaceRoleEnum.MEMBER)) {
    throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);
}
// after
if (!spaceUserService.isSpaceUser(spaceId, uid)) {
    if (!spaceUserService.addSpaceUser(spaceId, uid, SpaceRoleEnum.MEMBER)) {
        throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (spaceUserService.isSpaceUser(spaceId, applyUid)) { return ApiResult.success(); } // already a member

Try / catch

try { approve(...); } catch (BusinessException e) { if ("SPACE_USER_ADD_FAILED".equals(e.getMessage())) { /* check membership state, make operation idempotent, retry */ } }

Prevention

When it happens

Trigger: spaceUserService.addSpaceUser(spaceId, applyUid, SpaceRoleEnum.MEMBER) returns false — e.g. the user is already a member, the space no longer exists, or the user record write failed.

Common situations: Duplicate approvals racing so the user already exists; the applicant was deleted before approval; the target space was removed mid-flow; DB constraint violations on the membership table.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/90fa928f5fd40942. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/ApplyRecordBizServiceImpl.java:119

        ApplyRecord applyRecord = applyRecordService.getById(applyId);
        if (applyRecord == null) {
            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_RECORD_NOT_FOUND);
        }
        if (!Objects.equals(applyRecord.getSpaceId(), SpaceInfoUtil.getSpaceId())) {
            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_CURRENT_SPACE_INCONSISTENT);
        }
        if (!Objects.equals(applyRecord.getStatus(), ApplyRecord.Status.APPLYING.getCode())) {
            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_STATUS_INCORRECT);
        }
        applyRecord.setStatus(ApplyRecord.Status.APPROVED.getCode());
        applyRecord.setAuditTime(LocalDateTime.now());
        applyRecord.setAuditUid(RequestContextUtil.getUID());
        if (!applyRecordService.updateById(applyRecord)) {
            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_APPROVAL_FAILED);
        }
        // Add space user
        if (!spaceUserService.addSpaceUser(applyRecord.getSpaceId(), applyRecord.getApplyUid(), SpaceRoleEnum.MEMBER)) {
            throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);
        }
        return ApiResult.success();

    }

    /**
     * Reject application to join enterprise space
     *
     * @param applyId
     * @return
     */
    @Override
    @Transactional
    public ApiResult<String> refuseEnterpriseSpace(Long applyId) {
        ApplyRecord applyRecord = applyRecordService.getById(applyId);
        if (applyRecord == null) {
            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_RECORD_NOT_FOUND);
        }

View on GitHub (pinned to 5e758547a8)