{"record":{"id":"b39c0a855653c985","repo":"jackwener/OpenCLI","slug":"hf-spaces-failed-http-resp-status","errorCode":null,"errorMessage":"hf spaces failed: HTTP ${resp.status}","messagePattern":"hf spaces failed: HTTP (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hf/spaces.js","lineNumber":71,"sourceCode":"        if (sdk) url.searchParams.set('sdk', sdk);\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: { Accept: 'application/json', 'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)' },\n            });\n        }\n        catch (err) {\n            throw new CommandExecutionError(`hf spaces request failed: ${err?.message ?? err}`);\n        }\n        if (resp.status === 429) {\n            throw new CommandExecutionError(\n                'hf spaces returned HTTP 429 (rate limited)',\n                'Hugging Face throttles unauthenticated traffic; wait a few seconds and retry.',\n            );\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`hf spaces failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        }\n        catch (err) {\n            throw new CommandExecutionError(`hf spaces returned malformed JSON: ${err?.message ?? err}`);\n        }\n        const list = Array.isArray(data) ? data : [];\n        if (!list.length) {\n            throw new EmptyResultError('hf spaces', 'No matching spaces on huggingface.co.');\n        }\n        return list.slice(0, limit).map((s, i) => {\n            const id = String(s.id ?? s._id ?? '');\n            const slash = id.indexOf('/');\n            const author = String(s.author ?? (slash > 0 ? id.slice(0, slash) : ''));\n            const tags = Array.isArray(s.tags) ? s.tags.filter((t) => !String(t).startsWith('license:')).slice(0, 10).join(', ') : '';\n            return {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/spaces.js#L53-L89","documentation":"The Hugging Face Spaces API returned an HTTP status outside 2xx (other than the specially handled 429). The library surfaces the raw status code because the response body was not inspected, indicating the request was rejected or the endpoint changed.","triggerScenarios":"GET /api/spaces returns 404 (endpoint moved), 401/403 (restricted resource or blocked client), 5xx (HF server-side error), or any non-ok status while resp.status !== 429.","commonSituations":"HF API breaking changes or maintenance windows; corporate proxies returning 403/502 with their own error pages; malformed query parameters causing 400 responses.","solutions":["Check https://huggingface.co/docs/api-inference or the /api/spaces endpoint status directly with curl","Verify any query filters/parameters are valid for the current HF API","Retry later on 5xx (HF server-side issue)","Check whether a proxy is injecting 4xx/5xx responses"],"exampleFix":"// before: no diagnostics\nthrow new CommandExecutionError(`hf spaces failed: HTTP ${resp.status}`);\n// after\nconst body = await resp.text().catch(() => '');\nthrow new CommandExecutionError(`hf spaces failed: HTTP ${resp.status}: ${body.slice(0, 200)}`);","handlingStrategy":"try-catch","validationCode":"const probe = await fetch('https://huggingface.co/api/spaces?limit=1');\nif (!probe.ok) console.warn(`HF API unhealthy: HTTP ${probe.status}`);","typeGuard":null,"tryCatchPattern":"try {\n  await hfSpaces(query);\n} catch (e) {\n  const m = /HTTP (\\d{3})/.exec(e.message);\n  if (m) {\n    const status = Number(m[1]);\n    if (status >= 500) return retryLater();      // HF-side issue\n    if (status === 403 || status === 401) return checkAuthProxy(); // client env\n  }\n  throw e;\n}","preventionTips":["Monitor HF status before running bulk jobs","Keep query parameters valid for the current HF API","Check proxy behavior when statuses like 403/502 appear","Log response bodies for non-2xx to aid diagnosis"],"tags":["http","huggingface","api","cli"],"backgroundTag":"http-non-ok-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}