{"record":{"id":"bb8ae42fa06b4de6","repo":"iflytek/astron-agent","slug":"bot-belong-error","errorCode":"BOT_BELONG_ERROR","errorMessage":"BOT_BELONG_ERROR","messagePattern":"BOT_BELONG_ERROR","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"warning","filePath":"console/backend/commons/src/main/java/com/iflytek/astron/console/commons/service/bot/impl/BotFavoriteServiceImpl.java","lineNumber":206,"sourceCode":"        if (uid.equals(market.getUid())) {\n            market.setMine(true);\n        }\n        market.setIsFavorite(1);\n        market.setUid(null); // Hide sensitive data\n\n        if (\"en\".equals(langCode) && market.getBotNameEn() != null) {\n            market.setBotName(market.getBotNameEn());\n        }\n    }\n\n    @Override\n    public void create(String uid, Integer botId) {\n        QueryWrapper<ChatBotMarket> queryWrapper = new QueryWrapper<>();\n        queryWrapper.eq(\"bot_id\", botId);\n        ChatBotMarket chatBotMarket = chatBotMarketMapper.selectOne(queryWrapper);\n        // Bot not on shelf, and current uid is not equal to author uid, no permission to access\n        if (chatBotMarket != null && (chatBotMarket.getBotStatus() != 1 && chatBotMarket.getBotStatus() != 2 && chatBotMarket.getBotStatus() != 4 && !Objects.equals(chatBotMarket.getUid(), uid))) {\n            throw new BusinessException(ResponseEnum.BOT_BELONG_ERROR);\n        }\n        if (chatBotMarket == null) {\n            ChatBotBase botBase = chatBotBaseMapper.selectOne(Wrappers.lambdaQuery(ChatBotBase.class).eq(ChatBotBase::getId, botId).eq(ChatBotBase::getUid, uid));\n            if (botBase == null) {\n                throw new BusinessException(ResponseEnum.BOT_BELONG_ERROR);\n            }\n        }\n\n        BotFavorite botFavorite = botFavoriteMapper.selectOne(Wrappers.lambdaQuery(BotFavorite.class).eq(BotFavorite::getUid, uid).eq(BotFavorite::getBotId, botId));\n        if (botFavorite != null) {\n            log.error(\"[Assistant Favorite] User {} has already favorited assistant {}\", uid, botId);\n            return;\n        }\n\n        BotFavorite entity = BotFavorite.builder().uid(uid).botId(botId).createTime(LocalDateTime.now()).updateTime(LocalDateTime.now()).build();\n        botFavoriteMapper.insert(entity);\n    }\n","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/commons/src/main/java/com/iflytek/astron/console/commons/service/bot/impl/BotFavoriteServiceImpl.java#L188-L224","documentation":"BotFavoriteServiceImpl.create rejects favoriting a bot that is neither publicly available nor owned by the requesting user. If the market record exists but its botStatus is not 1/2/4 (shelved states) and the requester is not the author, it throws BusinessException with code BOT_BELONG_ERROR — an access-permission rejection.","triggerScenarios":"Calling create(uid, botId) where the bot is off-shelf (botStatus 0/3/etc.) and uid differs from the bot author's uid in chat_bot_market.","commonSituations":"Users trying to favorite a bot that was taken off the market; stale frontend pages listing delisted bots; bots restricted to their authors; wrong uid passed from the auth context.","solutions":["Check the bot's botStatus in chat_bot_market; only favorite bots with status 1, 2, or 4 (or your own bots)","Refresh the frontend bot list so delisted bots are no longer favoritable","Verify the authenticated uid matches the intended user (token/session mismatch can cause false denial)","Catch BusinessException with code BOT_BELONG_ERROR and show a friendly 'bot unavailable' message"],"exampleFix":"// before\nbotFavoriteService.create(uid, botId); // bot is off-shelf and not owned by uid\n// after\nChatBotMarket m = marketMapper.selectOne(new QueryWrapper<ChatBotMarket>().eq(\"bot_id\", botId));\nif (m == null || (m.getBotStatus() != 1 && m.getBotStatus() != 2 && m.getBotStatus() != 4\n        && !Objects.equals(m.getUid(), uid))) {\n    throw new BusinessException(ResponseEnum.BOT_BELONG_ERROR);\n}\nbotFavoriteService.create(uid, botId);","handlingStrategy":"try-catch","validationCode":"ChatBotMarket m = marketMapper.selectOne(new QueryWrapper<ChatBotMarket>().eq(\"bot_id\", botId)); boolean favoriteAllowed = m != null && (m.getBotStatus() == 1 || m.getBotStatus() == 2 || m.getBotStatus() == 4 || Objects.equals(m.getUid(), uid));","typeGuard":null,"tryCatchPattern":"try { botFavoriteService.create(uid, botId); } catch (BusinessException e) { if (ResponseEnum.BOT_BELONG_ERROR.getCode().equals(e.getCode())) return conflict(\"Bot not available for favoriting\"); throw e; }","preventionTips":["Only render favorite buttons for bots with status 1/2/4 or owned by the user","Keep bot lists refreshed; remove delisted bots from the UI promptly","Map BOT_BELONG_ERROR to a friendly client message"],"tags":["permission","bot","business-rule"],"backgroundTag":"permission-denied","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}