{"record":{"id":"c790ccdc690d5217","repo":"jackwener/OpenCLI","slug":"label-returned-http-resp-status-text","errorCode":null,"errorMessage":"${label} returned HTTP ${resp.status}${text ? `: ${text.slice(0, 200)}` : ''}","messagePattern":"(.+?) returned HTTP (.+?)(.+?)` : ''\\}","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/osv/utils.js","lineNumber":143,"sourceCode":"            headers: { 'user-agent': UA, accept: 'application/json', 'content-type': 'application/json' },\n            body: JSON.stringify(payload),\n        });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that api.osv.dev is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `OSV.dev returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(`${label} returned HTTP 429 (rate limited)`);\n    }\n    if (!resp.ok) {\n        const text = await resp.text().catch(() => '');\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}${text ? `: ${text.slice(0, 200)}` : ''}`);\n    }\n    return readJson(resp, label);\n}\n\n// Reduce OSV's `severity` array to a single human-readable label.\n// Returns null when no severity is recorded; never invents a value.\nexport function severityLabel(vuln) {\n    const dbSpecific = vuln?.database_specific;\n    if (dbSpecific && typeof dbSpecific.severity === 'string' && dbSpecific.severity.trim()) {\n        return dbSpecific.severity.trim();\n    }\n    const arr = Array.isArray(vuln?.severity) ? vuln.severity : [];\n    for (const entry of arr) {\n        if (entry && typeof entry.score === 'string' && entry.score.trim()) {\n            return entry.score.trim();\n        }\n    }\n    return null;","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/osv/utils.js#L125-L161","documentation":"osvPost received an unexpected non-ok HTTP status (not 404/429) from api.osv.dev. The error includes up to 200 characters of the response body to aid diagnosis — commonly a 4xx/5xx from the OSV API or an intermediary.","triggerScenarios":"osvPost to a querybatch endpoint got a status like 400 (malformed query payload), 403, 500, 502 or 503; the response body text is appended to the message when readable.","commonSituations":"Sending a malformed JSON payload or unsupported ecosystem name in the batch query (400); OSV.dev outage (5xx); corporate proxy rejecting the request (403/502); TLS interception returning an HTML error page.","solutions":["Read the appended response body in the error message — it usually names the exact problem (e.g. invalid query field)","Validate the payload: each query must use OSV's expected schema (version + package name + ecosystem)","Retry on 5xx with backoff; fix the payload on 4xx","Bypass intermediaries by testing the identical POST with curl to isolate proxy vs API issues"],"exampleFix":"// before\nawait osvPost(url, { queries: [{ package: { name: pkg } }] }, label);\n// after\nawait osvPost(url, { queries: [{ package: { name: pkg, ecosystem: 'npm' }, version: ver }] }, label);","handlingStrategy":"try-catch","validationCode":"const ecosystem = 'npm'; // must be an OSV-recognized ecosystem string\nif (!['npm','PyPI','Packagist','Go','Maven','crates.io','RubyGems','NuGet'].includes(ecosystem)) throw new Error(`Unsupported ecosystem: ${ecosystem}`);","typeGuard":"function isHttpError(err) { return err instanceof Error && /returned HTTP \\d{3}/.test(err.message); }","tryCatchPattern":"try {\n  return await osvBatch(payload);\n} catch (e) {\n  if (isHttpError(e)) {\n    console.error('OSV rejected request:', e.message); // body excerpt appended by the library\n    if (/HTTP 5\\d\\d/.test(e.message)) return retryWithBackoff(() => osvBatch(payload));\n  }\n  throw e;\n}","preventionTips":["Read the response-body excerpt included in the error message — it names the exact problem","Validate query payloads against the OSV querybatch schema before sending","Always include a valid ecosystem name in each package query","Retry only 5xx statuses; fix payloads on 4xx"],"tags":["http-error","api","osv"],"backgroundTag":"http-5xx-server-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}