{"record":{"id":"3fdd85101edcb74c","repo":"jackwener/OpenCLI","slug":"archive-snapshots-failed-http-resp-status","errorCode":null,"errorMessage":"archive snapshots failed: HTTP ${resp.status}","messagePattern":"archive snapshots failed: HTTP (.+?)","errorType":"http","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/archive/snapshots.js","lineNumber":79,"sourceCode":"        apiUrl.searchParams.set('url', target);\n        apiUrl.searchParams.set('output', 'json');\n        apiUrl.searchParams.set('limit', String(limit));\n        if (args.from) apiUrl.searchParams.set('from', String(args.from));\n        if (args.to) apiUrl.searchParams.set('to', String(args.to));\n\n        let resp;\n        try {\n            resp = await fetch(apiUrl, {\n                headers: {\n                    'Accept': 'application/json',\n                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`archive snapshots request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`archive snapshots failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        } catch (error) {\n            throw new CommandExecutionError(`archive snapshots returned malformed JSON: ${error?.message || error}`);\n        }\n\n        // CDX returns an array of arrays; the first row is the header.\n        if (!Array.isArray(data)) {\n            throw new CommandExecutionError('archive snapshots returned malformed CDX payload: top-level payload must be an array');\n        }\n        if (data.length < 2) {\n            throw new EmptyResultError('archive snapshots', `No Wayback snapshots for \"${target}\".`);\n        }\n        const [header, ...rows] = data;\n        if (!Array.isArray(header)) {\n            throw new CommandExecutionError('archive snapshots returned malformed CDX payload: header row must be an array');","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/archive/snapshots.js#L61-L97","documentation":"CommandExecutionError thrown when the Wayback CDX endpoint responds with a non-2xx HTTP status. The CDX service commonly returns 503 (per its docs, served on HTTP; HTTPS returns 503) or 4xx/5xx under load. The status code is embedded in the message so callers can branch on it.","triggerScenarios":"The fetch to http://web.archive.org/cdx/search/cdx succeeds at the transport level but resp.ok is false — e.g. HTTP 503 from overload or from hitting the HTTPS endpoint, 400 for a malformed url param, 403 for blocked clients.","commonSituations":"Wayback rate-limiting heavy automated use; CDX under maintenance/overload; malformed CDX query parameters (bad url= pattern, invalid filters); intermediaries returning 4xx/5xx HTML pages.","solutions":["Check the status in the message: 503 usually means retry later with exponential backoff.","Verify the target url pattern is valid CDX syntax (e.g. example.org or example.org/* for prefix matches).","Slow down request rate and add caching if you query many sites — Wayback enforces rate limits.","Confirm you are hitting the HTTP endpoint; the HTTPS CDX endpoint is known to return 503."],"exampleFix":"// before\nopencli archive snapshots 'https://example.org/path with space'\n// after\nopencli archive snapshots 'example.org/*'   # valid CDX url pattern, then retry on 503","handlingStrategy":"retry","validationCode":"// Validate the CDX url pattern before calling\nclassic: pattern = pattern || 'example.org';\nif (/[<>\"'\\s]/.test(pattern)) throw new Error(`invalid CDX url pattern: ${pattern}`);\nif (!Number.isInteger(limit) || limit <= 0 || limit > 1000) throw new Error('limit must be 1..1000');","typeGuard":null,"tryCatchPattern":"try {\n  await run(['archive', 'snapshots', url]);\n} catch (e) {\n  const m = /HTTP (\\d{3})/.exec(e.message);\n  if (m) {\n    const status = Number(m[1]);\n    if (status === 503 || status === 429) return retryWithBackoff(url); // transient\n    throw e; // 4xx: fix the url pattern/query\n  }\n  throw e;\n}","preventionTips":["Retry automatically on 503/429; fix the query on 4xx.","Throttle batch queries to respect Wayback rate limits.","Use valid CDX url patterns (domain or domain/*) to avoid 400s.","Cache snapshot results to reduce repeat hits on the CDX endpoint."],"tags":["http-status","network","archive-org","wayback","rate-limit"],"backgroundTag":"http-503","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}