{"record":{"id":"71cd9357449c3a41","repo":"DIYgod/RSSHub","slug":"invalid-data-received-from-api-71cd93","errorCode":null,"errorMessage":"Invalid data received from API","messagePattern":"Invalid data received from API","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"error","filePath":"lib/routes/skeb/works.ts","lineNumber":67,"sourceCode":"\n    const url = `${baseUrl}/api/users/${username.replace('@', '')}/works`;\n\n    await ensureRequestKey(url);\n\n    const items = await cache.tryGet(url, async () => {\n        const data = await ofetch(url, {\n            retry: 0,\n            method: 'GET',\n            query: { role: 'creator', sort: 'date', offset: '0' },\n            headers: {\n                'User-Agent': config.ua,\n                Cookie: `request_key=${await cache.get('skeb:request_key')}`,\n                Authorization: `Bearer ${config.skeb.bearerToken}`,\n            },\n        });\n\n        if (!data || !Array.isArray(data)) {\n            throw new Error('Invalid data received from API');\n        }\n\n        return data.map((item) => processWork(item)).filter(Boolean);\n    });\n\n    return {\n        title: `Skeb - ${username}'s Works`,\n        link: `${baseUrl}/${username}`,\n        item: items as DataItem[],\n    };\n}\n\nfunction hasResponseData(error: unknown): error is { response: { _data: string } } {\n    return error !== null && typeof error === 'object' && 'response' in error && typeof (error as { response?: { _data?: unknown } }).response?._data === 'string';\n}\n\nasync function ensureRequestKey(url: string) {\n    if (await cache.get('skeb:request_key')) {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/skeb/works.ts#L49-L85","documentation":"Thrown as a plain Error when the authenticated Skeb works API (/api/users/:username/works) returns a value that is falsy or not an array. Unlike the public API, this endpoint requires a valid bearer token and a request_key cookie. A non-array response typically indicates an auth failure (expired token), a rate-limit response, or that the username does not exist. The check `!data || !Array.isArray(data)` guards the subsequent data.map() call.","triggerScenarios":"The bearer token expired and the API returns a JSON error object instead of an array; the request_key cookie is stale or missing and Skeb returns a redirect/error page; the username does not exist (404 body); or Skeb returns a rate-limit response object.","commonSituations":"SKEB_BEARER_TOKEN was valid when set but has since expired; the request_key cache entry (skeb:request_key) was flushed and the key-rotation logic in ensureRequestKey failed to extract a new one; or the target creator's account was deleted/made private.","solutions":["Refresh the SKEB_BEARER_TOKEN by re-extracting it from the browser (localStorage.getItem('token')).","Clear the cached request_key if it is stale: flush the Redis/cache key 'skeb:request_key' and let ensureRequestKey re-fetch it.","Verify the username exists and is public by visiting https://skeb.jp/@username in a browser.","Check the raw API response by curling the works endpoint with the current token and cookie to see the error body."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!data || !Array.isArray(data)) {\n    throw new Error('Invalid data received from API — the bearer token may be expired or the username may not exist');\n}","typeGuard":"function isWorksArray(data: unknown): data is unknown[] {\n    return Array.isArray(data);\n}","tryCatchPattern":"try {\n    const data = await ofetch(url, { retry: 0, /* ... */ });\n    if (!isWorksArray(data)) throw new Error('Invalid data received from API');\n} catch (e) {\n    logger.error('Skeb works API call failed', { url, error: e });\n    throw e;\n}","preventionTips":["Regularly refresh the SKEB_BEARER_TOKEN before it expires.","Implement a health-check that probes the works endpoint periodically to catch token expiry early.","Log the HTTP status code and response body when the API returns non-array data to distinguish auth failures from rate limits."],"tags":["api","authentication","upstream","data-integrity","skeb"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}