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 accepting a SPACE-type invitation and adding the invitee to the space (ADMIN or MEMBER per the invite role) fails via spaceUserService.addSpaceUser returning false.

Solutions

  1. Make acceptance idempotent: if the user is already in the space, skip the add and continue
  2. Verify the space exists and is active before accepting
  3. Check spaceUserService logs/DB for the root write failure

Example fix

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

Strategy: validation

Validate before calling

if (spaceUserService.isSpaceUser(inviteRecord.getSpaceId(), inviteRecord.getInviteeUid())) { /* skip add, continue to enterprise check */ }

Try / catch

try { acceptInvite(inviteId); } catch (BusinessException e) { if ("SPACE_USER_ADD_FAILED".equals(e.getMessage())) { /* check if already member; verify space exists */ } }

Prevention

When it happens

Trigger: acceptInvite on a SPACE invitation where spaceUserService.addSpaceUser(spaceId, inviteeUid, role) returns false — already a member, space deleted, or the membership write failed.

Common situations: Double-clicking accept on an invite; the space was deleted while the invite was pending; DB constraint violations on the space-user table.

Related errors


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

Appendix: source

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

        if (responseMsg != null) {
            return responseMsg;
        }
        // Update invitation record
        inviteRecord.setStatus(InviteRecordStatusEnum.ACCEPT.getCode());
        if (!inviteRecordService.updateById(inviteRecord)) {
            return ApiResult.error(ResponseEnum.OPERATION_FAILED);
        }
        // For enterprise invitation, add enterprise user
        if (InviteRecordTypeEnum.ENTERPRISE.getCode().equals(inviteRecord.getType())) {
            if (!enterpriseUserService.addEnterpriseUser(inviteRecord.getEnterpriseId(), inviteRecord.getInviteeUid(),
                    Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? EnterpriseRoleEnum.GOVERNOR : EnterpriseRoleEnum.STAFF)) {
                throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);
            }
            // Add space user
        } else if (InviteRecordTypeEnum.SPACE.getCode().equals(inviteRecord.getType())) {
            if (!spaceUserService.addSpaceUser(inviteRecord.getSpaceId(), inviteRecord.getInviteeUid(),
                    Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? SpaceRoleEnum.ADMIN : SpaceRoleEnum.MEMBER)) {
                throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);
            }
            Space space = spaceService.getSpaceById(inviteRecord.getSpaceId());
            // For enterprise space invitation, if not joined team, add user
            if (space.getEnterpriseId() != null) {
                if (!enterpriseUserService.addEnterpriseUser(space.getEnterpriseId(), inviteRecord.getInviteeUid(),
                        Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? EnterpriseRoleEnum.GOVERNOR : EnterpriseRoleEnum.STAFF)) {
                    throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);
                }
            }
        } else {
            throw new BusinessException(ResponseEnum.INVITE_UNSUPPORTED_TYPE);
        }
        return ApiResult.success();
    }

    /**
     * Decline invitation
     *

View on GitHub (pinned to 5e758547a8)