sickn33/agentic-awesome-skills · error · Error

HTTP ${response.status}

Error message

HTTP ${response.status}

What it means

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.

Source

Thrown at skills/fp-refactor/SKILL.md:1139

const range = (start: number, end: number): readonly number[] =>
  RA.unfold(start, (n) => (n <= end ? O.some([n, n + 1]) : O.none));
```

---

## 6. Migrating Promise chains to TaskEither

### Pattern: Promise.then chains to pipe

#### Before (Imperative)

```typescript
function fetchUserData(userId: string): Promise<UserProfile> {
  return fetch(`/api/users/${userId}`)
    .then((response) => {
      if (!response.ok) {
        throw new Error(`HTTP ${response.status}`);
      }
      return response.json();
    })
    .then((data) => validateUserData(data))
    .then((validData) => enrichUserProfile(validData))
    .catch((error) => {
      console.error('Failed to fetch user data:', error);
      throw error;
    });
}

// Chained promises with conditionals
function processOrder(orderId: string): Promise<OrderResult> {
  return getOrder(orderId)
    .then((order) => {
      if (order.status === 'cancelled') {
        throw new Error('Order is cancelled');
      }

View on GitHub (pinned to 58d857988f)

Solutions

  1. Extract a checked fetch helper that throws typed status errors once and reuse it across pipelines
  2. Surface per-status UI (re-login on 401, retry on 5xx)
  3. Convert the chain to TE.pipe composition per the skill so each failure keeps its position context

Example fix

// before
.then((response) => {
  if (!response.ok) throw new Error(`HTTP ${response.status}`)
  return response.json()
})

// after
const getJson = (url: string) =>
  TE.tryCatch(async () => {
    const r = await fetch(url)
    if (!r.ok) throw new Error(`HTTP ${r.status}`)
    return r.json()
  }, E.toError)
Defensive patterns

Strategy: try-catch

Try / catch

fetchUserData(userId).catch((error) => {
  const status = /HTTP (\d+)/.exec(error.message)?.[1]
  if (status === '401') { /* re-auth then retry once */ }
  else throw error
})

Prevention

When it happens

Trigger: GET /api/users/:userId responding 4xx/5xx — auth failure, unknown id, or gateway error — inside a .then pipeline of fetch → json → validate → enrich.

Common situations: Profile pages fetching during token refresh windows; API base URL differences between environments; enrich endpoints moved causing upstream 404s.

Related errors


AI-assisted analysis of sickn33/agentic-awesome-skills@58d857988f (2026-08-26). Data as JSON: /api/errors/4368cb510e06f4ca. Report an issue: GitHub.