{"record":{"id":"521b9ca72268bd32","repo":"iflytek/astron-agent","slug":"invite-add-team-user-failed-521b9c","errorCode":"INVITE_ADD_TEAM_USER_FAILED","errorMessage":"INVITE_ADD_TEAM_USER_FAILED","messagePattern":"INVITE_ADD_TEAM_USER_FAILED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/InviteRecordBizServiceImpl.java","lineNumber":264,"sourceCode":"     */\n    @Override\n    @Transactional\n    public ApiResult<String> acceptInvite(Long inviteId) {\n        InviteRecord inviteRecord = inviteRecordService.getById(inviteId);\n        ApiResult<String> responseMsg = checkInviteRecord(inviteRecord);\n        if (responseMsg != null) {\n            return responseMsg;\n        }\n        // Update invitation record\n        inviteRecord.setStatus(InviteRecordStatusEnum.ACCEPT.getCode());\n        if (!inviteRecordService.updateById(inviteRecord)) {\n            return ApiResult.error(ResponseEnum.OPERATION_FAILED);\n        }\n        // For enterprise invitation, add enterprise user\n        if (InviteRecordTypeEnum.ENTERPRISE.getCode().equals(inviteRecord.getType())) {\n            if (!enterpriseUserService.addEnterpriseUser(inviteRecord.getEnterpriseId(), inviteRecord.getInviteeUid(),\n                    Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? EnterpriseRoleEnum.GOVERNOR : EnterpriseRoleEnum.STAFF)) {\n                throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);\n            }\n            // Add space user\n        } else if (InviteRecordTypeEnum.SPACE.getCode().equals(inviteRecord.getType())) {\n            if (!spaceUserService.addSpaceUser(inviteRecord.getSpaceId(), inviteRecord.getInviteeUid(),\n                    Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? SpaceRoleEnum.ADMIN : SpaceRoleEnum.MEMBER)) {\n                throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);\n            }\n            Space space = spaceService.getSpaceById(inviteRecord.getSpaceId());\n            // For enterprise space invitation, if not joined team, add user\n            if (space.getEnterpriseId() != null) {\n                if (!enterpriseUserService.addEnterpriseUser(space.getEnterpriseId(), inviteRecord.getInviteeUid(),\n                        Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? EnterpriseRoleEnum.GOVERNOR : EnterpriseRoleEnum.STAFF)) {\n                    throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);\n                }\n            }\n        } else {\n            throw new BusinessException(ResponseEnum.INVITE_UNSUPPORTED_TYPE);\n        }","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/InviteRecordBizServiceImpl.java#L246-L282","documentation":"INVITE_ADD_TEAM_USER_FAILED is thrown when accepting an ENTERPRISE-type invitation and adding the invitee to the enterprise (as GOVERNOR for admin invites, STAFF otherwise) fails. The invite cannot be completed because the enterprise membership write returned false.","triggerScenarios":"Calling acceptInvite for an enterprise invitation where enterpriseUserService.addEnterpriseUser returns false — invitee already a member, enterprise deleted, or membership write failed.","commonSituations":"User clicking an invite link twice; the enterprise was disbanded before acceptance; admin invitee already exists with a different role; DB errors on the enterprise-user table.","solutions":["Check if the invitee is already an enterprise member and treat as success/idempotent","Verify the enterprise still exists before accepting the invite","Inspect enterpriseUserService for the underlying failure and re-run acceptance"],"exampleFix":"// before\nif (!enterpriseUserService.addEnterpriseUser(eid, uid, role)) {\n    throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);\n}\n// after\nif (!enterpriseUserService.isEnterpriseUser(eid, uid)\n        && !enterpriseUserService.addEnterpriseUser(eid, uid, role)) {\n    throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);\n}","handlingStrategy":"validation","validationCode":"if (enterpriseUserService.getEnterpriseUser(inviteRecord.getEnterpriseId(), inviteRecord.getInviteeUid()) != null) { return ApiResult.success(); } // already a member","typeGuard":null,"tryCatchPattern":"try { acceptInvite(inviteId); } catch (BusinessException e) { if (\"INVITE_ADD_TEAM_USER_FAILED\".equals(e.getMessage())) { /* mark invite accepted-if-member; verify enterprise still exists */ } }","preventionTips":["Mark invite records consumed to prevent double acceptance","Validate the enterprise exists and is active before accepting","Make membership adds idempotent"],"tags":["invite","enterprise","membership"],"backgroundTag":"database-write-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}