{"record":{"id":"c0503e1c5f6b2e3a","repo":"iflytek/astron-agent","slug":"unauthorized-responseenum","errorCode":"UNAUTHORIZED","errorMessage":"ResponseEnum.UNAUTHORIZED","messagePattern":"ResponseEnum\\.UNAUTHORIZED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/impl/AgentMemoryServiceImpl.java","lineNumber":223,"sourceCode":"                item.createdAt(),\n                item.updatedAt());\n    }\n\n    private AgentMemoryConfigDto defaultDto(Integer botId) {\n        AgentMemoryConfigDto dto = new AgentMemoryConfigDto();\n        dto.setBotId(botId);\n        dto.setProvider(Mem0MemoryProvider.PROVIDER);\n        dto.setEnabled(false);\n        dto.setHasApiKey(false);\n        dto.setAutoSearch(true);\n        dto.setSearchTopK(DEFAULT_TOP_K);\n        dto.setMinScore(DEFAULT_MIN_SCORE);\n        return dto;\n    }\n\n    private void validateUser(String uid) {\n        if (StringUtils.isBlank(uid)) {\n            throw new BusinessException(ResponseEnum.UNAUTHORIZED);\n        }\n    }\n\n    private void checkBotPermission(String uid, Long spaceId, Integer botId) {\n        if (botId == null || chatBotBaseMapper.checkBotPermission(botId, uid, spaceId) <= 0) {\n            throw new BusinessException(ResponseEnum.INSUFFICIENT_PERMISSIONS);\n        }\n    }\n\n    private void addSpaceCondition(LambdaQueryWrapper<AgentMemoryConfig> queryWrapper, Long spaceId) {\n        queryWrapper.eq(AgentMemoryConfig::getSpaceId, toStoredSpaceId(spaceId));\n    }\n\n    private String normalizeProvider(String provider) {\n        String normalized = StringUtils.upperCase(StringUtils.trimToEmpty(provider));\n        return StringUtils.isBlank(normalized) ? Mem0MemoryProvider.PROVIDER : normalized;\n    }\n","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/impl/AgentMemoryServiceImpl.java#L205-L241","documentation":"AgentMemoryServiceImpl.validateUser throws UNAUTHORIZED when the uid argument is blank. Every public entry point (getConfig, saveConfig, listMemories, deleteMemory, clearMemories) funnels through it, so this means the request reached the service without an authenticated user id.","triggerScenarios":"Any agent-memory endpoint invoked with a null/empty uid — typically a missing, expired, or malformed auth token so the interceptor did not populate the uid context.","commonSituations":"Calling the API without a login session; token expired so user context resolution failed; internal calls that bypass the auth filter and pass uid=null.","solutions":["Ensure the request carries a valid authentication token/session so the framework resolves the uid.","Re-authenticate if the token expired, then retry.","Check that the auth interceptor/filter correctly extracts and forwards uid to the service layer."],"exampleFix":"// before\nhttpClient.get(\"/agent-memory/config?botId=1\"); // no auth header\n// after\nhttpClient.get(\"/agent-memory/config?botId=1\",\n    { headers: { Authorization: `Bearer ${token}` } });","handlingStrategy":"try-catch","validationCode":"if (!authToken || isExpired(authToken)) { await reauthenticate(); }","typeGuard":null,"tryCatchPattern":"try { await memApi.getConfig(botId); } catch (e) { if (e.status === 401 || e.code === 'UNAUTHORIZED') { redirectToLogin(); } }","preventionTips":["Attach the Authorization header via a shared HTTP interceptor.","Handle 401 globally with token refresh and retry.","Never call memory endpoints from unauthenticated contexts."],"tags":["auth","unauthorized","validation"],"backgroundTag":"authentication-required","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"}