{"record":{"id":"abb574bb79ed8a18","repo":"mastra-ai/mastra","slug":"request-failed-res-status-server-provided-m-abb574","errorCode":null,"errorMessage":"Request failed (${res.status}) / server-provided message","messagePattern":"Request failed \\((.+?)\\) / server-provided message","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory-ui/src/ui/domains/factory/services/factory.ts","lineNumber":80,"sourceCode":"  for (const [key, value] of Object.entries(params ?? {})) {\n    if (value !== undefined) search.set(key, value);\n  }\n  const query = search.size === 0 ? '' : `?${search}`;\n  const url = `${baseUrl}/web/github/projects/${encodeURIComponent(githubProjectId)}/${resource}${query}`;\n  const res = await fetch(url, {\n    headers: { Accept: 'application/json' },\n    credentials: 'include',\n  });\n  if (!res.ok) {\n    let message = `Request failed (${res.status})`;\n    try {\n      const body = (await res.json()) as { error?: string; message?: string };\n      if (body.message) message = body.message;\n      else if (body.error) message = body.error;\n    } catch {\n      /* ignore non-JSON */\n    }\n    throw new Error(message);\n  }\n  return (await res.json()) as T;\n}\n\n/** List one page of a connected repository's open GitHub issues (PRs excluded server-side). */\nexport async function listRepositoryIssues(\n  baseUrl: string,\n  githubProjectId: string,\n  page: number,\n  label?: string,\n): Promise<GithubIssuePage> {\n  return getRepositoryResource<GithubIssuePage>(baseUrl, githubProjectId, 'issues', { page: String(page), label });\n}\n\n/** List one page of a connected repository's open pull requests (drafts excluded server-side). */\nexport async function listRepositoryPullRequests(\n  baseUrl: string,\n  githubProjectId: string,","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory-ui/src/ui/domains/factory/services/factory.ts#L62-L98","documentation":"getRepositoryResource is the shared fetch wrapper for GitHub repository resources (issues, PRs) in the factory service. On any non-OK response it throws an Error whose message prefers the server JSON body's message then error field, falling back to 'Request failed (<status>)'. It exists to translate backend/GitHub-proxy failures into a single consistent error for callers.","triggerScenarios":"Any non-OK res.status from listRepositoryIssues, listRepositoryPullRequests, getRepositoryIssue, or getRepositoryPullRequest: 404 for a nonexistent issue/PR/repo, 401/403 when the GitHub connection is not authorized, 400 for malformed resourceId, or 5xx from the server.","commonSituations":"GitHub App/subscription revoked so the resource is no longer accessible, requesting an issue or PR number that does not exist or was deleted, wrong resourceId/threadId after switching projects, or rate-limit (429) from GitHub through the server proxy.","solutions":["Read error.message: a server-provided message (e.g. GitHub 'Not Found') tells you the actual cause; otherwise use the status code","Confirm the GitHub connection for the project is still authorized and the repo is accessible","Verify the issue/PR number and resourceId exist in the connected repository","If 429/5xx, wait and retry with backoff"],"exampleFix":"// before\nconst pr = await getRepositoryPullRequest(baseUrl, 'bad-resource-id', 99999999);\n// after\nif (!resourceId) throw new Error('Connect a repository first');\nconst pr = await getRepositoryPullRequest(baseUrl, resourceId, prNumber);","handlingStrategy":"try-catch","validationCode":"if (!Number.isInteger(resourceIdNumber) || resourceIdNumber <= 0) throw new Error('Invalid issue/PR number');\nif (!isNonEmptyString(resourceId)) throw new Error('Connect a repository before listing issues');","typeGuard":"function isGitHubResource<T>(body: unknown): body is T {\n  return typeof body === 'object' && body !== null;\n}","tryCatchPattern":"try {\n  const issues = await listRepositoryIssues(baseUrl, resourceId);\n} catch (err) {\n  const msg = err instanceof Error ? err.message : String(err);\n  if (msg.includes('404')) showEmptyState('Resource not found — check the repository connection');\n  else if (msg.includes('401') || msg.includes('403')) showReconnectGitHub();\n  else showRetryableError(msg);\n}","preventionTips":["Verify the GitHub App installation/authorization is still valid before listing resources","Check issue/PR numbers exist before fetching details","Handle 429 by backing off instead of hammering the proxy","Surface server-provided messages (already preferred by the helper) directly to users"],"tags":["http","api","github"],"backgroundTag":"http-request-failed-with-status","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}