srbhr/Resume-Matcher · error · Error
Improve failed with status ${response.status}: ${text}
Error message
Improve failed with status ${response.status}: ${text} What it means
postImprove in apps/frontend/lib/api/resume.ts throws this Error when the improve endpoint returns a non-OK HTTP status, embedding both the status code and the FULL raw response body in the message. The body is also logged via console.error beforehand. Because the raw body is included, the message can be very long or contain HTML/JSON internals.
Source
Thrown at apps/frontend/lib/api/resume.ts:134
async function postImprove(
endpoint: string,
payload: Record<string, unknown>
): Promise<ImprovedResult> {
let response: Response;
try {
// Use the configurable request timeout so NEXT_PUBLIC_REQUEST_TIMEOUT_MS
// actually applies to the long-running improve/preview/confirm calls (#776).
response = await apiPost(endpoint, payload, DEFAULT_TIMEOUT_MS);
} catch (networkError) {
console.error(`Network error during ${endpoint}:`, networkError);
throw networkError;
}
const text = await response.text();
if (!response.ok) {
console.error('Improve failed response body:', text);
throw new Error(`Improve failed with status ${response.status}: ${text}`);
}
try {
return JSON.parse(text) as ImprovedResult;
} catch (parseError) {
console.error('Failed to parse improve response:', parseError, 'Raw response:', text);
throw parseError;
}
}
/** Uploads job descriptions and returns a job_id */
export async function uploadJobDescriptions(
descriptions: string[],
resumeId: string
): Promise<string> {
const res = await apiPost('/jobs/upload', {
job_descriptions: descriptions,
resume_id: resumeId,View on GitHub (pinned to 116f9cc3b0)
Solutions
- Read the status and body in the thrown message (or console output) to classify: 401 re-auth, 404 verify resumeId, 422 fix payload schema, 5xx check backend/AI provider.
- For 422, validate the improve request payload against the current API schema before sending.
- Retry with backoff only for 429/502/503/504; surface a clean message to users instead of the raw body.
- Check backend logs and AI provider configuration (keys, quota, timeout) for persistent 5xx.
- Verify the API base URL/route matches the deployed backend version.
Example fix
// before
const text = await response.text();
if (!response.ok) {
console.error('Improve failed response body:', text);
throw new Error(`Improve failed with status ${response.status}: ${text}`);
}
// after
const text = await response.text();
if (!response.ok) {
console.error('Improve failed response body:', text);
let detail = '';
try { detail = JSON.parse(text)?.detail ?? ''; } catch { /* non-JSON */ }
throw new Error(detail || `Improve failed with status ${response.status}`);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!resumeId?.trim()) throw new Error('resumeId is required for improve.'); Type guard
function isImproveError(e: unknown): e is Error & { status?: number } {
return e instanceof Error && e.message.startsWith('Improve failed with status');
} Try / catch
try {
const improved = await improveResume(resumeId);
} catch (e) {
if (isImproveError(e)) {
const status = Number(e.message.match(/status (\d+)/)?.[1] ?? 0);
if (status === 401) redirectToLogin();
else if (status === 429 || status >= 500) showToast('Service busy — retrying shortly.');
else showToast('Improvement failed. Please check your input and retry.');
} else throw e;
} Prevention
- Parse status out of the message or, better, attach status to a custom error class at the API layer.
- Do not display the raw message to users — it can include the full HTML/JSON response body.
- Retry with backoff on 429/5xx only; handle 401 with re-authentication.
When it happens
Trigger: The fetch (after a prior network failure was rethrown) resolves with response.ok === false: 401 auth failure, 404 unknown resume, 422 request payload fails schema validation, 429 rate limit, or 5xx from the AI improvement backend. It then reads the full text and throws with status plus body.
Common situations: Gateway/proxy returns an HTML error page (502/504) flooding the error message; request schema drifted from backend after an API update (422); auth cookie expired (401); LLM provider out of quota producing 500.
Related errors
- ${data.detail || Failed to regenerate content (status ${res.
- ${text || Resume wizard turn failed with status ${response.s
- ${text || Resume wizard finalize failed with status ${respon
- ${data.detail || Failed to analyze resume (status ${res.stat
- ${data.detail || Failed to generate enhancements (status ${r
AI-assisted analysis of srbhr/Resume-Matcher@116f9cc3b0 (2026-08-28).
Data as JSON: /api/errors/0db9cdfcba21fa0d.
Report an issue: GitHub.