{"record":{"id":"59e5d44c6a56fb1c","repo":"jackwener/OpenCLI","slug":"label-returned-api-status-statuscode-status","errorCode":null,"errorMessage":"${label} returned API status ${statusCode}${statusText ? ` (${statusText})` : ''}","messagePattern":"(.+?) returned API status (.+?)(.+?)\\)` : ''\\}","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/dblp/utils.js","lineNumber":73,"sourceCode":"export async function dblpFetchJson(path, label) {\n    const res = await dblpFetch(`${DBLP_ORIGIN}${path}`, label, 'application/json');\n    let body;\n    try {\n        body = await res.json();\n    }\n    catch (err) {\n        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);\n    }\n    const statusCode = String(body?.result?.status?.['@code'] ?? '').trim();\n    if (!statusCode) {\n        throw new CommandExecutionError(\n            `${label} returned JSON without result.status.@code`,\n            'dblp changed its JSON envelope or returned a partial error payload; inspect the raw response in a browser.',\n        );\n    }\n    if (statusCode !== '200') {\n        const statusText = String(body?.result?.status?.text ?? '').trim();\n        throw new CommandExecutionError(\n            `${label} returned API status ${statusCode}${statusText ? ` (${statusText})` : ''}`,\n            'dblp accepted the HTTP request but reported an API-level failure. Retry later or inspect the same query in a browser.',\n        );\n    }\n    return body;\n}\n\nexport async function dblpFetchXml(path, label) {\n    const res = await dblpFetch(`${DBLP_ORIGIN}${path}`, label, 'application/xml');\n    return res.text();\n}\n\nexport function coerceInt(value) {\n    if (value === undefined || value === null || value === '') return NaN;\n    const n = typeof value === 'number' ? value : Number(value);\n    return Number.isFinite(n) && Number.isInteger(n) ? n : NaN;\n}\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/dblp/utils.js#L55-L91","documentation":"Thrown when HTTP succeeded but dblp's JSON envelope reports an API-level status code other than 200 (with optional status text). dblp accepted the request but its own API layer rejected or failed the query.","triggerScenarios":"body.result.status['@code'] parses but !== '200' — e.g. dblp API returns status 400 for a bad query, 404 for unknown resources, or 5xx at the API layer.","commonSituations":"Malformed or unsupported search queries; dblp API-side incidents returning non-200 inside an HTTP-200 envelope; deprecated/changed query parameters.","solutions":["Retry later — API-level 5xx is often transient","Simplify or correct the query string and re-run","Open the same query in a browser to read result.status.text for the exact API error","Check dblp's search API FAQ for parameter changes"],"exampleFix":"// before\nconst q = '';\nconst json = await dblpFetchJson(`/search/publ/api?q=${q}&format=json`, 'dblp search'); // API status 400\n// after\nconst q = 'database';\nconst json = await dblpFetchJson(`/search/publ/api?q=${encodeURIComponent(q)}&format=json`, 'dblp search');","handlingStrategy":"retry","validationCode":"const q = encodeURIComponent(query.trim());\nif (!q || q === '%20') throw new Error('Query must contain non-whitespace characters');","typeGuard":"function isApiOk(body) { return String(body?.result?.status?.['@code'] ?? '') === '200'; }","tryCatchPattern":"try {\n  const json = await dblpFetchJson(path, 'dblp search');\n} catch (err) {\n  const m = /API status (\\d+)/.exec(err.message);\n  if (m && m[1].startsWith('5')) {\n    await new Promise(r => setTimeout(r, 3000));\n    return retryFetch(path); // API-side transient failure\n  }\n  if (m && m[1] === '400') {\n    console.error('Query rejected by dblp — simplify the search terms');\n    return null;\n  }\n  throw err;\n}","preventionTips":["Read result.status.text (surfaced in the error) for the exact API failure","Retry 5xx API statuses with backoff; fix the query for 4xx","Test the exact query in a browser to confirm what dblp accepts","Keep queries simple and URL-encoded"],"tags":["dblp","api","http"],"backgroundTag":"api-level-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}