{"record":{"id":"c5ca433d390afdda","repo":"DIYgod/RSSHub","slug":"techflow-api-returned-an-invalid-newsflash-list","errorCode":null,"errorMessage":"TechFlow API returned an invalid newsflash list.","messagePattern":"TechFlow API returned an invalid newsflash list\\.","errorType":"exception","errorClass":"TypeError","httpStatus":503,"severity":"error","filePath":"lib/routes/techflowpost/utils.ts","lineNumber":177,"sourceCode":"            cache.tryGet(`techflowpost:article:${article.id}`, async () => {\n                const itemLink = `${rootUrl}/${locale}/article/${article.id}`;\n                const detail = await requestApi<ArticleDetailResponse>(`/client/articles/${article.id}`, itemLink);\n\n                return getArticleItem(article, detail.article?.content);\n            })\n        )\n    );\n}\n\nasync function getNewsflashItems(limit: string | number) {\n    const link = `${rootUrl}/${locale}/newsletter`;\n    const response = await requestApi<ApiListResponse<Newsflash>>('/client/newsflashes', link, {\n        page: 1,\n        page_size: limit,\n    });\n\n    if (!Array.isArray(response.data)) {\n        throw new TypeError('TechFlow API returned an invalid newsflash list.');\n    }\n\n    return await Promise.all(\n        response.data.map((newsflash) =>\n            cache.tryGet(`techflowpost:newsflash:${newsflash.id}`, async () => {\n                const itemLink = `${rootUrl}/${locale}/newsletter/${newsflash.id}`;\n                const detail = await requestApi<NewsflashDetailResponse>(`/client/newsflashes/${newsflash.id}`, itemLink);\n\n                return getNewsflashItem(newsflash, detail.content);\n            })\n        )\n    );\n}\n\nexport { getArticleItems, getNewsflashItems, rootUrl };\n","sourceCodeStart":159,"sourceCodeEnd":193,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/techflowpost/utils.ts#L159-L193","documentation":"Same guard pattern as the article list, applied to GET /client/newsflashes. After a successful (non-challenge) request, if response.data is not an Array the route rejects it as an invalid newsflash list. Indicates the newsflash endpoint changed its envelope or returned an error object.","triggerScenarios":"Calling GET {apiRoot}/client/newsflashes with page=1 and page_size=limit where the server returns {data: {...}} or {code, msg} instead of {data: [...]}. Common when the newsletter/newsflash feature is toggled off or the endpoint is renamed.","commonSituations":"TechFlow deprecates or restructures the newsflash endpoint; a temporary outage returns an error JSON object; the newsflash section is gated behind a locale/plan that the request did not satisfy.","solutions":["Log the raw response to determine the new envelope (e.g. response.data.items) and update the ApiListResponse<Newsflash> type and the Array check.","Confirm the endpoint path /client/newsflashes is still correct in the current TechFlow API.","If the feature is removed, retire the route or point it at the replacement endpoint.","Mirror the article-list hardening: accept a nested array before throwing."],"exampleFix":"// before\nif (!Array.isArray(response.data)) {\n    throw new TypeError('TechFlow API returned an invalid newsflash list.');\n}\n\n// after\nconst list = Array.isArray(response.data) ? response.data : response.data?.items;\nif (!Array.isArray(list)) {\n    throw new TypeError(`TechFlow API returned an invalid newsflash list: ${JSON.stringify(response).slice(0, 200)}`);\n}","handlingStrategy":"type-guard","validationCode":"function isNewsflashList(r: unknown): r is { data: unknown[] } {\n    return !!r && typeof r === 'object' && Array.isArray((r as any).data);\n}","typeGuard":"function isNewsflashListResponse(r: unknown): r is { data: Newsflash[] } {\n    return typeof r === 'object' && r !== null && Array.isArray((r as { data?: unknown }).data);\n}","tryCatchPattern":"try {\n    const response = await requestApi<ApiListResponse<Newsflash>>('/client/newsflashes', link, params);\n    return isNewsflashListResponse(response) ? response.data : [];\n} catch (e) {\n    if (e instanceof TypeError && /invalid newsflash list/.test(e.message)) {\n        return []; // graceful degradation\n    }\n    throw e;\n}","preventionTips":["Wrap list-fetching helpers with a type guard so a shape change degrades rather than throws.","Confirm /client/newsflashes is still the active endpoint before relying on it.","Log the response body on shape failure to detect API drift quickly.","Share one isListResponse guard between the article and newsflash fetchers."],"tags":["api-contract","validation","typescript","parsing"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}