Skip to content

Commit

Permalink
APIレスポンスにerrorsとdataの両方を含む場合はエラーを無視する
Browse files Browse the repository at this point in the history
原因不明だが SearchTimeline のレスポンスで起こることがある
  • Loading branch information
upsilon committed Nov 20, 2023
1 parent b51c625 commit cbdc8bf
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 0 deletions.
8 changes: 8 additions & 0 deletions OpenTween.Tests/Api/GraphQL/ErrorResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@ public void ThrowIfError_SuccessResponseTest()
ErrorResponse.ThrowIfError(responseText);
// 通常のレスポンスに対しては WebApiException を発生させない
}

[Fact]
public void ThrowIfError_SuccessWithErrorResponseTest()
{
var responseText = File.ReadAllText("Resources/Responses/SearchTimeline_SuccessWithError.json");
ErrorResponse.ThrowIfError(responseText);
// errors と data の両方を含むレスポンスに対してはエラーを無視する
}
}
}
3 changes: 3 additions & 0 deletions OpenTween.Tests/OpenTween.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<None Update="Resources\Responses\SearchTimeline_SimpleTweet.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\SearchTimeline_SuccessWithError.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\TimelineTweet_PromotedTweet.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
{
"errors": [
{
"message": "Authorization: Denied by access control: unspecified reason",
"locations": [
{
"line": 2380,
"column": 3
}
],
"path": [
"search_by_raw_query",
"search_timeline",
"timeline",
"instructions",
0,
"entries",
8,
"content",
"itemContent",
"tweet_results",
"result",
"quoted_status_result",
"result",
"birdwatch_pivot"
],
"extensions": {
"name": "AuthorizationError",
"source": "Client",
"code": 37,
"kind": "Permissions",
"tracing": {
"trace_id": "f8221ca3841a88b7"
}
},
"code": 37,
"kind": "Permissions",
"name": "AuthorizationError",
"source": "Client",
"tracing": {
"trace_id": "f8221ca3841a88b7"
}
}
],
"data": {
"search_by_raw_query": {
"search_timeline": {
"timeline": {
"instructions": [
{
"type": "TimelineAddEntries",
"entries": [
{
"entryId": "tweet-1619433164757413894",
"sortIndex": "1725509634359296000",
"content": {
"entryType": "TimelineTimelineItem",
"__typename": "TimelineTimelineItem",
"itemContent": {
"itemType": "TimelineTweet",
"__typename": "TimelineTweet",
"tweet_results": {
"result": {
"__typename": "Tweet",
"rest_id": "1613784711020826626",
"core": {
"user_results": {
"result": {
"__typename": "User",
"id": "VXNlcjo0MDQ4MDY2NA==",
"rest_id": "40480664",
"affiliates_highlighted_label": {},
"has_graduated_access": true,
"is_blue_verified": false,
"profile_image_shape": "Circle",
"legacy": {
"followed_by": true,
"following": true,
"can_dm": true,
"can_media_tag": true,
"created_at": "Sat May 16 15:20:01 +0000 2009",
"default_profile": false,
"default_profile_image": false,
"description": "OpenTween Project 言い出しっぺ",
"entities": {
"description": {
"urls": []
},
"url": {
"urls": [
{
"display_url": "m.upsilo.net/@upsilon",
"expanded_url": "https://m.upsilo.net/@upsilon",
"url": "https://t.co/vNMmyHHOQD",
"indices": [
0,
23
]
}
]
}
},
"fast_followers_count": 0,
"favourites_count": 216272,
"followers_count": 1301,
"friends_count": 917,
"has_custom_timelines": false,
"is_translator": false,
"listed_count": 92,
"location": "Funabashi, Chiba, Japan",
"media_count": 1040,
"name": "upsilon",
"normal_followers_count": 1301,
"pinned_tweet_ids_str": [],
"possibly_sensitive": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/40480664/1349188016",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/719076434/____normal.png",
"profile_interstitial_type": "",
"screen_name": "kim_upsilon",
"statuses_count": 10096,
"translator_type": "regular",
"url": "https://t.co/vNMmyHHOQD",
"verified": false,
"want_retweets": true,
"withheld_in_countries": []
}
}
}
},
"edit_control": {
"edit_tweet_ids": [
"1613784711020826626"
],
"editable_until_msecs": "1673593032000",
"is_edit_eligible": true,
"edits_remaining": "5"
},
"edit_perspective": {
"favorited": false,
"retweeted": false
},
"is_translatable": true,
"views": {
"count": "403",
"state": "EnabledWithCount"
},
"source": "<a href=\"https://www.opentween.org/\" rel=\"nofollow\">OpenTween (dev)</a>",
"legacy": {
"bookmark_count": 1,
"bookmarked": false,
"created_at": "Fri Jan 13 06:27:12 +0000 2023",
"conversation_id_str": "1613784711020826626",
"display_text_range": [
0,
20
],
"entities": {
"user_mentions": [],
"urls": [],
"hashtags": [],
"symbols": []
},
"favorite_count": 6,
"favorited": false,
"full_text": "この数年おきに来るAPI凍結騒動は何なの",
"is_quote_status": false,
"lang": "ja",
"quote_count": 0,
"reply_count": 0,
"retweet_count": 0,
"retweeted": false,
"user_id_str": "40480664",
"id_str": "1613784711020826626"
}
}
},
"tweetDisplayType": "Tweet"
},
"clientEventInfo": {
"component": "result",
"element": "tweet",
"details": {
"timelinesDetails": {
"controllerData": "DAACDAAFDAABDAABDAABCgABAAAAAAAAAAAAAAwAAgoAAQAAAAAAAABACgACeZLCPXeFB4ULAAMAAAAOZnJvbTpvcGVudHdlZW4KAAVI5p7pPhun5QgABgAAABIKAAdKf1o1dSI7xgAAAAAA"
}
}
}
}
}
]
},
{
"type": "TimelineReplaceEntry",
"entry_id_to_replace": "cursor-top-9223372036854775807",
"entry": {
"entryId": "cursor-top-9223372036854775807",
"sortIndex": "9223372036854775807",
"content": {
"entryType": "TimelineTimelineCursor",
"__typename": "TimelineTimelineCursor",
"value": "DAADDAABCgABF_YPZVuaQM0KAAIX3xt2G1vAowAIAAIAAAABCAADAAAAAAgABAAAAAEKAAUX9lgCXIAnEAoABhf2WAJcf7HgAAA",
"cursorType": "Top"
}
}
},
{
"type": "TimelineReplaceEntry",
"entry_id_to_replace": "cursor-bottom-0",
"entry": {
"entryId": "cursor-bottom-0",
"sortIndex": "0",
"content": {
"entryType": "TimelineTimelineCursor",
"__typename": "TimelineTimelineCursor",
"value": "DAADDAABCgABF_YPZVuaQM0KAAIX3xt2G1vAowAIAAIAAAACCAADAAAAAAgABAAAAAEKAAUX9lgCXIAnEAoABhf2WAJcf7HgAAA",
"cursorType": "Bottom"
}
}
}
]
}
}
}
}
}
4 changes: 4 additions & 0 deletions OpenTween/Api/GraphQL/ErrorResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static void ThrowIfError(string? jsonString)

public static void ThrowIfError(XElement rootElm)
{
// errors と data プロパティが両方ともある場合はエラーを無視して正常なレスポンスとして扱う
if (rootElm.Element("data")?.HasElements == true)
return;

var errorsElm = rootElm.Element("errors") ?? null;
if (errorsElm == null)
return;
Expand Down

0 comments on commit cbdc8bf

Please sign in to comment.