{"record":{"id":"c3f6d748334a99aa","repo":"lobehub/lobehub","slug":"failed-to-get-agent-group-list-response-statust","errorCode":null,"errorMessage":"Failed to get agent group list: ${response.statusText}","messagePattern":"Failed to get agent group list: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/server/src/routers/lambda/market/agentGroup.ts","lineNumber":578,"sourceCode":"\n        if (!headers['x-lobe-trust-token'] && accessToken) {\n          headers['Authorization'] = `Bearer ${accessToken}`;\n        }\n\n        const response = await fetch(listUrl, {\n          headers,\n          method: 'GET',\n        });\n\n        if (!response.ok) {\n          const errorText = await response.text();\n          log(\n            'Get agent group list failed: %s %s - %s',\n            response.status,\n            response.statusText,\n            errorText,\n          );\n          throw new Error(`Failed to get agent group list: ${response.statusText}`);\n        }\n\n        const result = await response.json();\n        log('Get agent group list success: count=%d', result.totalCount);\n\n        // Transform items to match getGroupAgentList format from DiscoverService\n        const transformedItems = (result.items || []).map((group: any) => ({\n          author: group.author || '',\n          avatar: group.avatar || '👥',\n          category: group.category,\n          createdAt: group.createdAt,\n          description: group.description || '',\n          homepage: discoverUrl('group_agent', group.identifier),\n          identifier: group.identifier,\n          installCount: group.installCount || 0,\n          isFeatured: group.isFeatured || false,\n          isOfficial: group.isOfficial || false,\n          isValidated: group.isValidated,","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/lobehub/lobehub/blob/10f24d7ade75139093a9373b364f6bc91f3cd7db/apps/server/src/routers/lambda/market/agentGroup.ts#L560-L596","documentation":"Inner throw in `getAgentGroupList` (agentGroup.ts:578) when the GET to `${MARKET_BASE_URL}/api/v1/agent-group/list` returns non-2xx. The message embeds the upstream `statusText`, which is what the client ultimately sees after the outer catch preserves `error.message`. This is a read operation scoped by pagination query params (`page`, `pageSize`).","triggerScenarios":"Market list endpoint returns 401/403 (no/invalid auth token), 400 (invalid `page`/`pageSize`/`category` query), 5xx (Market outage); Market under heavy load timing out.","commonSituations":"Discover page loads before auth middleware has populated `marketOidcAccessToken`; pagination state corrupted on the client so `page` is 0 or negative and Market rejects it; Market deploy missing the `/agent-group/list` route version expected by this client.","solutions":["Read the `statusText` embedded in the message to classify: 'Unauthorized' → auth, 'Bad Request' → query params, 'Internal Server Error' → upstream.","Validate pagination inputs on the client (`page >= 1`, `pageSize` within Market's allowed range) before calling the procedure.","Confirm auth: `DEBUG=lambda-router:market:agent-group` shows whether `x-lobe-trust-token` or `Authorization` was attached.","curl `MARKET_BASE_URL/api/v1/agent-group/list?page=1&pageSize=20` with the bearer token to isolate client vs upstream."],"exampleFix":"// before\nthrow new Error(`Failed to get agent group list: ${response.statusText}`);\n// after — include the parsed upstream body so 'Bad Request' reasons are visible\nthrow new Error(`Failed to get agent group list (${response.status}): ${errorText || response.statusText}`);","handlingStrategy":"validation","validationCode":"// Validate pagination before calling the list endpoint\nif (!Number.isInteger(page) || page < 1) throw new Error('page must be >= 1');\nif (!Number.isInteger(pageSize) || pageSize < 1 || pageSize > 100) throw new Error('pageSize out of range');","typeGuard":"function isAgentGroupList(v: unknown): v is { items: unknown[]; totalCount: number; currentPage: number; pageSize: number; totalPages: number } {\n  const r = v as Record<string, unknown>;\n  return !!r && Array.isArray(r.items) && typeof r.totalCount === 'number';\n}","tryCatchPattern":"try {\n  const list = await trpc.market.agentGroup.getAgentGroupList.query({ page, pageSize });\n} catch (e) {\n  const msg = (e as Error)?.message ?? '';\n  if (/unauthorized|forbidden/i.test(msg)) { /* re-auth */ }\n  else if (/bad request/i.test(msg)) { /* fix pagination */ }\n  else throw e;\n}","preventionTips":["Clamp page/pageSize to Market's accepted range on the client.","Ensure auth context is populated before the first list fetch.","Confirm MARKET_BASE_URL and the /agent-group/list route version."],"tags":["trpc","market-api","fetch","pagination","auth"],"backgroundTag":null,"analyzedSha":"10f24d7ade75139093a9373b364f6bc91f3cd7db","analyzedAt":"2026-08-12T11:43:19.543Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}