srbhr/Resume-Matcher · error · Error

${data.detail || Failed to apply enhancements (status ${res.

Error message

${data.detail || Failed to apply enhancements (status ${res.status}).}

What it means

applyEnhancements in apps/frontend/lib/api/enrichment.ts throws this Error when the POST to `/enrichment/apply/{resumeId}` returns a non-OK response. It surfaces the backend `detail` message when present, otherwise a generic message with the HTTP status. It means the server refused or failed to persist the chosen enhancements onto the resume.

Source

Thrown at apps/frontend/lib/api/enrichment.ts:99

  }

  return res.json();
}

/**
 * Apply enhancements to the master resume.
 */
export async function applyEnhancements(
  resumeId: string,
  enhancements: EnhancedDescription[]
): Promise<{ message: string; updated_items: number }> {
  const res = await apiPost(`/enrichment/apply/${resumeId}`, {
    enhancements,
  });

  if (!res.ok) {
    const data = await res.json().catch(() => ({}));
    throw new Error(data.detail || `Failed to apply enhancements (status ${res.status}).`);
  }

  return res.json();
}

// ============================================
// AI Regenerate Feature Types
// ============================================

export interface RegenerateItemInput {
  item_id: string;
  item_type: 'experience' | 'project' | 'skills';
  title: string;
  subtitle?: string;
  current_content: string[];
}

export interface RegenerateRequest {

View on GitHub (pinned to 116f9cc3b0)

Solutions

  1. Check res.status first: 401 -> re-authenticate; 404 -> verify the resume still exists; 422 -> validate the enhancements payload; 5xx -> inspect backend logs.
  2. Ensure the enhancements being applied came from the current generation response and were not mutated/emptied before submit.
  3. Re-fetch the resume after a 404 and inform the user the resume no longer exists.
  4. Add idempotency/retry only for network-level failures and 502/503/504, not for 4xx.
  5. Confirm the API base URL and route version match the backend deployment.

Example fix

// before
if (!res.ok) {
  const data = await res.json().catch(() => ({}));
  throw new Error(data.detail || `Failed to apply enhancements (status ${res.status}).`);
}
// after
if (!res.ok) {
  if (enhancements.length === 0) throw new Error('No enhancements selected to apply.');
  const data = await res.json().catch(() => ({}));
  throw new Error(data.detail || `Failed to apply enhancements (status ${res.status}).`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!resumeId?.trim() || !Array.isArray(enhancements) || enhancements.length === 0) {
  throw new Error('Cannot apply: missing resumeId or no enhancements selected.');
}

Type guard

function isApplicableEnhancements(v: unknown): v is EnhancementPreview[] {
  return Array.isArray(v) && v.length > 0 && v.every(x =>
    typeof x === 'object' && x !== null && 'item_id' in x);
}

Try / catch

try {
  await applyEnhancements(resumeId, selectedEnhancements);
} catch (e) {
  const msg = e instanceof Error ? e.message : '';
  if (msg.includes('status 404')) showError('This resume no longer exists.');
  else if (msg.includes('status 401')) redirectToLogin();
  else showError('Applying changes failed. Your selections are preserved — please retry.');
}

Prevention

When it happens

Trigger: apiPost(`/enrichment/apply/${resumeId}`, { enhancements }) yields 401 (no valid session), 404 (resumeId not found), 422 (enhancements array empty or items missing required fields like id/content), or 5xx (database write failure / backend crash while saving).

Common situations: User clicks Apply after the resume was deleted elsewhere (404); stale enhancement objects from an older API version fail validation (422); the database is unavailable or the update transaction fails (500); auth cookie expired mid-flow (401).

Related errors


AI-assisted analysis of srbhr/Resume-Matcher@116f9cc3b0 (2026-08-28). Data as JSON: /api/errors/c02ca8664f62afe8. Report an issue: GitHub.