{"record":{"id":"6d021176b9c58b77","repo":"jackwener/OpenCLI","slug":"message-describetwitterapierror-tweetresultbyres","errorCode":null,"errorMessage":"message (describeTwitterApiError('TweetResultByRestId', rawResult.httpStatus))","messagePattern":"message \\(describeTwitterApiError\\('TweetResultByRestId', rawResult\\.httpStatus\\)\\)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/twitter/article.js","lineNumber":251,"sourceCode":"          else if (blockType === 'code-block')       parts.push('\\`\\`\\`\\\\n' + text + '\\\\n\\`\\`\\`');\n          else                                       parts.push(text);\n        }\n\n        return [{\n          title,\n          author: screenName,\n          content: parts.join('\\\\n\\\\n') || legacy.full_text || '',\n          url: 'https://x.com/' + screenName + '/status/' + tweetId,\n        }];\n      }\n    `));\n        if (!Array.isArray(rawResult) && !isPlainObject(rawResult)) {\n            throw new CommandExecutionError('Twitter article response payload is malformed');\n        }\n        if (rawResult?.httpStatus) {\n            const message = describeTwitterApiError('TweetResultByRestId', rawResult.httpStatus);\n            if (rawResult.httpStatus === 401 || rawResult.httpStatus === 403) {\n                throw new AuthRequiredError('x.com', message);\n            }\n            throw new CommandExecutionError(message);\n        }\n        if (rawResult?.error) {\n            throw new CommandExecutionError(rawResult.error + (rawResult.hint ? ` (${rawResult.hint})` : ''));\n        }\n        if (!Array.isArray(rawResult)) {\n            throw new CommandExecutionError('Twitter article response payload is malformed');\n        }\n        return rawResult;\n    }\n});\n","sourceCodeStart":233,"sourceCodeEnd":264,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/article.js#L233-L264","documentation":"When the TweetResultByRestId response carries an httpStatus, describeTwitterApiError maps it to a human-readable message which is thrown: 401/403 become AuthRequiredError('x.com', message); any other status becomes a CommandExecutionError with that message. This surfaces the actual Twitter API error (rate limit, blocked, auth rejected) with the right error class.","triggerScenarios":"The in-page fetch to the Twitter GraphQL endpoint returns a response with an httpStatus field — e.g. 401/403 for expired or insufficient auth, 429 rate limit, or other HTTP failures from api.x.com/graphql/TweetResultByRestId.","commonSituations":"Expired x.com session (401), account restrictions or private content (403), heavy scraping triggering 429 rate limits, or Twitter API changes altering endpoint behavior.","solutions":["For 401/403: re-run twitter login to refresh the session cookies","For 429: wait and retry later; reduce request volume","Check the mapped message for the specific status meaning and follow its hint","Verify the account can access the requested tweet (protected/deleted content yields auth/forbidden errors)"],"exampleFix":"// before\nnode cli.js twitter article <id>   // stale session -> 401\n// after\nnode cli.js twitter login && node cli.js twitter article <id>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAuthStatus(status) { return status === 401 || status === 403; }","tryCatchPattern":"import { AuthRequiredError } from '@jackwener/opencli/errors';\ntry {\n  await articleCmd({ tweetId });\n} catch (err) {\n  if (err instanceof AuthRequiredError) {\n    await runTwitterLogin();\n    return articleCmd({ tweetId }); // one retry after re-auth\n  }\n  if (err.message.includes('429') || /rate limit/i.test(err.message)) {\n    await sleep(60_000);\n    return articleCmd({ tweetId });\n  }\n  throw err;\n}","preventionTips":["Refresh login sessions proactively to avoid 401/403","Throttle request volume to avoid 429 rate limits","Read the mapped describeTwitterApiError message for the exact cause","Check account access to protected/deleted content before fetching"],"tags":["api","http","auth","twitter"],"backgroundTag":"twitter-api-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}