{"record":{"id":"a41f40b5b8a008a9","repo":"Freika/dawarich","slug":"settings-failed-to-check-recalculation-status","errorCode":null,"errorMessage":"[Settings] Failed to check recalculation status:","messagePattern":"\\[Settings\\] Failed to check recalculation status:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/javascript/controllers/maps/maplibre/settings_manager.js","lineNumber":485,"sourceCode":"      if (!apiKey) {\n        console.warn(\n          \"[Settings] No API key available for recalculation status check\",\n        )\n        return\n      }\n\n      const response = await fetch(\n        \"/api/v1/settings/transportation_recalculation_status\",\n        {\n          headers: {\n            Authorization: `Bearer ${apiKey}`,\n            \"Content-Type\": \"application/json\",\n          },\n        },\n      )\n\n      if (!response.ok) {\n        console.warn(\n          \"[Settings] Failed to check recalculation status:\",\n          response.status,\n        )\n        return\n      }\n\n      const data = await response.json()\n      this.updateRecalculationUI(data)\n    } catch (error) {\n      console.error(\"[Settings] Error checking recalculation status:\", error)\n    }\n  }\n\n  /**\n   * Update UI based on recalculation status\n   */\n  updateRecalculationUI(status) {\n    const controller = this.controller","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/Freika/dawarich/blob/97fad417c5a11b0eb11157890635e015723a2e97/app/javascript/controllers/maps/maplibre/settings_manager.js#L467-L503","documentation":"The status poll fetched /api/v1/settings/transportation_recalculation_status with a Bearer API key and received a non-2xx response. The handler logs the HTTP status and returns early, leaving the recalculation progress UI showing stale state. Network-level failures are handled separately by the outer catch, which logs 'Error checking recalculation status'.","triggerScenarios":"401 when the API key is invalid, revoked, or belongs to a deleted user; 404 on an older backend build that predates the endpoint; 429 rate limiting from the poll cadence; 500 when the recalculation state store errors; gateway 502/504 during deploys.","commonSituations":"Regenerating the API key in settings while a map tab stays open with the old key; upgrading the frontend ahead of the backend so the endpoint is missing; self-hosted instances behind rate-limiting proxies; server errors during heavy recalculation jobs.","solutions":["Match the logged status: 401 → regenerate/re-enter the API key and reload; 404 → update the Dawarich backend to a version with the endpoint; 429 → slow the poll interval; 5xx → check server logs","Verify the key directly: curl -H 'Authorization: Bearer <key>' .../api/v1/settings/transportation_recalculation_status","Align frontend and backend versions after partial upgrades","Back off polling on repeated failures instead of hammering the endpoint"],"exampleFix":"// before\nif (!response.ok) {\n  console.warn(\"[Settings] Failed to check recalculation status:\", response.status)\n  return\n}\n// after\nif (!response.ok) {\n  if (response.status === 401) {\n    this.updateRecalculationUI({ status: \"unauthorized\" })\n    return // key revoked — stop polling until reload\n  }\n  console.warn(\"[Settings] Failed to check recalculation status:\", response.status)\n  this.pollIntervalMs = Math.min(this.pollIntervalMs * 2, 60000)\n  return\n}","handlingStrategy":"validation","validationCode":"if (!apiKey) { this.updateRecalculationUI({ status: \"unknown\" }); return }\nconst probe = await fetch(\"/api/v1/health\", {\n  headers: { Authorization: `Bearer ${apiKey}` },\n})\nif (probe.status === 401) { showReauthPrompt(); return }","typeGuard":null,"tryCatchPattern":"try {\n  const response = await fetch(url, { headers })\n  if (response.status === 401) return // key revoked: stop polling, prompt re-auth\n  if (!response.ok) { console.warn(\"[Settings] Failed to check recalculation status:\", response.status); backOff(); return }\n  this.updateRecalculationUI(await response.json())\n} catch (error) {\n  console.error(\"[Settings] Error checking recalculation status:\", error)\n}","preventionTips":["Handle 401 distinctly: stop the poll and prompt for a fresh key instead of warning forever","Back off exponentially on repeated non-2xx responses","Re-read the key on window focus so regenerated keys take effect without a full reload"],"tags":["fetch","http-status","api-key","dawarich","settings"],"backgroundTag":"fetch-non-2xx-response","analyzedSha":"97fad417c5a11b0eb11157890635e015723a2e97","analyzedAt":"2026-08-21T17:04:17.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}