{"record":{"id":"4368cb510e06f4ca","repo":"sickn33/agentic-awesome-skills","slug":"http-response-status-4368cb","errorCode":null,"errorMessage":"HTTP ${response.status}","messagePattern":"HTTP \\$\\{response\\.status\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skills/fp-refactor/SKILL.md","lineNumber":1139,"sourceCode":"\nconst range = (start: number, end: number): readonly number[] =>\n  RA.unfold(start, (n) => (n <= end ? O.some([n, n + 1]) : O.none));\n```\n\n---\n\n## 6. Migrating Promise chains to TaskEither\n\n### Pattern: Promise.then chains to pipe\n\n#### Before (Imperative)\n\n```typescript\nfunction fetchUserData(userId: string): Promise<UserProfile> {\n  return fetch(`/api/users/${userId}`)\n    .then((response) => {\n      if (!response.ok) {\n        throw new Error(`HTTP ${response.status}`);\n      }\n      return response.json();\n    })\n    .then((data) => validateUserData(data))\n    .then((validData) => enrichUserProfile(validData))\n    .catch((error) => {\n      console.error('Failed to fetch user data:', error);\n      throw error;\n    });\n}\n\n// Chained promises with conditionals\nfunction processOrder(orderId: string): Promise<OrderResult> {\n  return getOrder(orderId)\n    .then((order) => {\n      if (order.status === 'cancelled') {\n        throw new Error('Order is cancelled');\n      }","sourceCodeStart":1121,"sourceCodeEnd":1157,"githubUrl":"https://github.com/sickn33/agentic-awesome-skills/blob/58d857988fcfac6986206bca2b2fe223aa437e4b/skills/fp-refactor/SKILL.md#L1121-L1157","documentation":"In fp-refactor's promise-chain example, fetchUserData throws this inside the first .then when the /api/users/:userId response is not ok. Because it throws inside a .then, it propagates to the chain's .catch, demonstrating how promise chains need central catch handling.","triggerScenarios":"GET /api/users/:userId responding 4xx/5xx — auth failure, unknown id, or gateway error — inside a .then pipeline of fetch → json → validate → enrich.","commonSituations":"Profile pages fetching during token refresh windows; API base URL differences between environments; enrich endpoints moved causing upstream 404s.","solutions":["Extract a checked fetch helper that throws typed status errors once and reuse it across pipelines","Surface per-status UI (re-login on 401, retry on 5xx)","Convert the chain to TE.pipe composition per the skill so each failure keeps its position context"],"exampleFix":"// before\n.then((response) => {\n  if (!response.ok) throw new Error(`HTTP ${response.status}`)\n  return response.json()\n})\n\n// after\nconst getJson = (url: string) =>\n  TE.tryCatch(async () => {\n    const r = await fetch(url)\n    if (!r.ok) throw new Error(`HTTP ${r.status}`)\n    return r.json()\n  }, E.toError)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"fetchUserData(userId).catch((error) => {\n  const status = /HTTP (\\d+)/.exec(error.message)?.[1]\n  if (status === '401') { /* re-auth then retry once */ }\n  else throw error\n})","preventionTips":["Use one shared checked-fetch helper for all pipelines","Retry only idempotent GETs on 5xx"],"tags":["http","promise-chain","fetch","network"],"backgroundTag":"http-error-status","analyzedSha":"58d857988fcfac6986206bca2b2fe223aa437e4b","analyzedAt":"2026-08-26T11:55:59.350Z","schemaVersion":2},"datasetVersion":"2026-08-26T14:46:13.012Z"}