{"record":{"id":"e188fc6f6dc4b3a8","repo":"jackwener/OpenCLI","slug":"request-failed-result-status-result-status","errorCode":null,"errorMessage":"Request failed: ${result?.status} ${result?.statusText} (${result?.url || url})","messagePattern":"Request failed: (.+?) (.+?) \\((.+?)\\)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/uiverse/_shared.js","lineNumber":70,"sourceCode":"    const response = await fetch(url, {\n      credentials: 'include',\n      headers: {\n        accept: 'application/json, text/plain, */*',\n      },\n    });\n    const text = await response.text();\n    return JSON.stringify({\n      ok: response.ok,\n      status: response.status,\n      statusText: response.statusText,\n      text,\n      url,\n    });\n  })()`);\n\n  const result = JSON.parse(raw);\n  if (!result?.ok) {\n    throw new Error(`Request failed: ${result?.status} ${result?.statusText} (${result?.url || url})`);\n  }\n\n  try {\n    return JSON.parse(result.text);\n  } catch {\n    throw new Error(`Response was not valid JSON: ${url}`);\n  }\n}\n\nexport async function getPostDetails(page, input) {\n  const normalized = parseComponentInput(input);\n  await page.goto(normalized.url);\n\n  const raw = await page.evaluate(`(async () => {\n    const key = ${JSON.stringify(ROUTE_DATA_KEY)};\n    const loaderData = window.__remixContext?.state?.loaderData || {};\n    const routeData = loaderData[key];\n    return JSON.stringify({ routeData: routeData || null, keys: Object.keys(loaderData) });","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/uiverse/_shared.js#L52-L88","documentation":"Thrown by fetchJsonInBrowser when the fetch executed inside the Playwright/Puppeteer page returns a non-ok HTTP response. The error includes the status, statusText, and the requested URL, so it surfaces any 404/500/blocked request made against uiverse.io route-data or code-resource endpoints.","triggerScenarios":"getPostDetails falling back to the ?_data=routes/$username.$friendlyId endpoint for a component that does not exist (404); getRawCode hitting /resource/post/code/<postId> with a stale or invalid postId; uiverse.io returning 5xx or a 403 from rate limiting / bot protection (Cloudflare challenge); expired session cookies when credentials:'include' no longer authenticates.","commonSituations":"Typo in author/slug leading to a nonexistent page whose loader endpoint 404s; scraping while uiverse.io deploys and its Remix data endpoints change; heavy scraping triggering WAF blocks; network/proxy outage producing 502/503.","solutions":["Verify the author/slug is valid by opening the component URL in a browser","Retry after a delay with backoff — 429/5xx are often transient rate limits or deploys","Run the browser headed and check for Cloudflare/bot-protection interstitials; solve the challenge or use a residential/stealth setup","Log in within the browser page if the resource requires authentication (cookies are sent via credentials:'include')"],"exampleFix":"// before\nconst details = await getPostDetails(page, input); // 404 for typo slug\n// after\ntry {\n  const details = await getPostDetails(page, input);\n} catch (e) {\n  if (e.message.includes('404')) throw new Error(`Component not found: ${input}`);\n  await new Promise(r => setTimeout(r, 5000)); // retry on 429/5xx\n  const details = await getPostDetails(page, input);\n}","handlingStrategy":"retry","validationCode":"// Cannot fully pre-validate server state, but verify the component exists in a browser first:\nawait page.goto(`https://uiverse.io/${author}/${slug}`);\nconst notFound = await page.locator('text=Page Not Found').count();\nif (notFound) throw new Error(`Component ${author}/${slug} does not exist`);","typeGuard":"const isFailedStatus = (status) => status === 0 || status === 403 || status === 404 || status === 429 || status >= 500;","tryCatchPattern":"try {\n  const payload = await getRawCode(page, postId);\n} catch (e) {\n  if (e.message.startsWith('Request failed')) {\n    if (/(429|5\\d\\d)/.test(e.message)) {\n      await sleep(5000); // retry transient failures with backoff\n      return getRawCode(page, postId);\n    }\n    if (e.message.includes('404')) throw new Error(`Resource not found: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Verify author/slug by opening the page in a real browser before batch scraping","Throttle requests (delay between calls) to avoid 429 rate limits","Keep a logged-in browser session for authenticated resources","Run headed or with stealth plugins if bot protection returns 403"],"tags":["network","http","scraping"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}