mastra-ai/mastra · error
Request failed (${res.status}) / server-provided message
Error message
Request failed (${res.status}) / server-provided message What it means
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.
Source
Thrown at mastracode/factory-ui/src/ui/domains/factory/services/factory.ts:80
for (const [key, value] of Object.entries(params ?? {})) {
if (value !== undefined) search.set(key, value);
}
const query = search.size === 0 ? '' : `?${search}`;
const url = `${baseUrl}/web/github/projects/${encodeURIComponent(githubProjectId)}/${resource}${query}`;
const res = await fetch(url, {
headers: { Accept: 'application/json' },
credentials: 'include',
});
if (!res.ok) {
let message = `Request failed (${res.status})`;
try {
const body = (await res.json()) as { error?: string; message?: string };
if (body.message) message = body.message;
else if (body.error) message = body.error;
} catch {
/* ignore non-JSON */
}
throw new Error(message);
}
return (await res.json()) as T;
}
/** List one page of a connected repository's open GitHub issues (PRs excluded server-side). */
export async function listRepositoryIssues(
baseUrl: string,
githubProjectId: string,
page: number,
label?: string,
): Promise<GithubIssuePage> {
return getRepositoryResource<GithubIssuePage>(baseUrl, githubProjectId, 'issues', { page: String(page), label });
}
/** List one page of a connected repository's open pull requests (drafts excluded server-side). */
export async function listRepositoryPullRequests(
baseUrl: string,
githubProjectId: string,View on GitHub (pinned to 75dd419e61)
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
Example fix
// before
const pr = await getRepositoryPullRequest(baseUrl, 'bad-resource-id', 99999999);
// after
if (!resourceId) throw new Error('Connect a repository first');
const pr = await getRepositoryPullRequest(baseUrl, resourceId, prNumber); Defensive patterns
Strategy: try-catch
Validate before calling
if (!Number.isInteger(resourceIdNumber) || resourceIdNumber <= 0) throw new Error('Invalid issue/PR number');
if (!isNonEmptyString(resourceId)) throw new Error('Connect a repository before listing issues'); Type guard
function isGitHubResource<T>(body: unknown): body is T {
return typeof body === 'object' && body !== null;
} Try / catch
try {
const issues = await listRepositoryIssues(baseUrl, resourceId);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (msg.includes('404')) showEmptyState('Resource not found — check the repository connection');
else if (msg.includes('401') || msg.includes('403')) showReconnectGitHub();
else showRetryableError(msg);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Perplexity Search request failed with status ${response.stat
- GitHub OAuth token exchange failed: ${res.status}
- Request failed (${response.status}) / server-provided messag
- Failed to load pull request subscriptions (${response.status
- Request failed (${res.status}) / server-provided message
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/abb574bb79ed8a18.
Report an issue: GitHub.