fix(route/twitter): defensive fallback for missing profile_image_url (avoid /twitter/user/* 503)#22137
Open
Dinglingyun2022 wants to merge 1 commit into
Conversation
When api.getUser() returns user info without profile_image_url (observed when X changes API contract, see DIYgod#22136), the unguarded .replace() call on user.ts:91 throws TypeError and the entire /twitter/user/* route returns 503. Add optional chaining + fallback to X's default profile image, allowing the route to degrade gracefully instead of crashing the whole feed. This is a defensive guard only; the root cause (X API contract change) is tracked in DIYgod#22136 and requires updates to gql-id-resolver / query IDs / GraphQL features.
Contributor
|
Please use actual values in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Involved Issue / 该 PR 相关 Issue
Defensive guard related to #22136 (does not fix the root cause; see "Scope" below).
Example for the Proposed Route(s) / 路由地址示例
New RSS Route Checklist / 新 RSS 路由检查表
namespace.tsis included /namespace.ts中含有 作者Note / 说明
Summary
lib/routes/twitter/user.ts:91callsprofileImageUrl.replace(...)without optional chaining. Whenapi.getUser(id)returns user info whoseprofile_image_url/profile_image_url_httpsfields are missing (observed when X changes the API contract — see #22136),profileImageUrlresolves toundefined, and the unguarded.replace()call throwsTypeError: Cannot read properties of undefined (reading 'replace'), making the entire/twitter/user/*route return HTTP 503.Diff
One-line change: add optional chaining and fall back to X's official default profile image when the field is missing.
Scope
profile_image_urlto be missing in the first place) is tracked in twitter: /twitter/user/* return 503 (TypeError in gql-id-resolver) + /twitter/keyword/* return 404 (regression on master 2026-05-29) #22136 and requires updates togql-id-resolver/ query IDs / GraphQL features inlib/routes/twitter/api/web-api/.profileImageUrlis present, behavior is unchanged.Why this is still valuable even after #22136 root cause lands
This is a generic defensive guard against future X API contract changes. X has historically renamed / removed fields on
UserByScreenNamemultiple times. With this guard in place, future similar regressions degrade gracefully (default avatar) instead of crashing the entire route with a confusingTypeError.Symptom reference (from #22136)