fix: handle partial errors in TweetDetail API responses
Twitter API sometimes returns partial errors (e.g., is_translatable field failures) alongside valid thread data. Previously, any error caused the entire request to fail even when usable data was present. Now we check if threaded_conversation_with_injections_v2.instructions exists before failing on errors, allowing successful thread fetching despite non-fatal API errors. Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
committed by
Peter Steinberger
co-authored by
Claude Opus 4.5
parent
57c8e8e793
commit
35b8774b1c
@@ -216,7 +216,14 @@ export function withTweetDetails<TBase extends AbstractConstructor<TwitterClient
|
||||
};
|
||||
|
||||
if (data.errors && data.errors.length > 0) {
|
||||
return { success: false as const, error: data.errors.map((e) => e.message).join(', ') };
|
||||
// Check if we still have usable data despite errors.
|
||||
// Twitter API sometimes returns partial errors (e.g., is_translatable field failures)
|
||||
// alongside valid thread data. Only fail if no usable data is present.
|
||||
const hasUsableData = data.data?.threaded_conversation_with_injections_v2?.instructions?.length;
|
||||
if (!hasUsableData) {
|
||||
return { success: false as const, error: data.errors.map((e) => e.message).join(', ') };
|
||||
}
|
||||
// Continue with partial data despite non-fatal errors
|
||||
}
|
||||
|
||||
return { success: true as const, data: data.data ?? {} };
|
||||
|
||||
Reference in New Issue
Block a user