Skip to content

Commit

Permalink
Fix: [Server][Utils/TwitterGraphQLAPI] GraphQL API へのアクセスに失敗するようになってい…
Browse files Browse the repository at this point in the history
…た問題を修正

responsive_web_grok_analyze_button_fetch_trends_enabled フラグの静的解析に一部失敗しており、デフォルト値が featureSwitch に含まれていなかったのが原因らしい
  • Loading branch information
tsukumijima committed Dec 8, 2024
1 parent cc088ef commit 04b0ac0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic import Field
from pydantic import RootModel
from tortoise.contrib.pydantic import PydanticModel
from typing import Annotated, Any, Literal, Union
from typing import Annotated, Literal, Union
from typing_extensions import TypedDict


Expand Down Expand Up @@ -532,7 +532,7 @@ class TwitterGraphQLAPIEndpointInfo(BaseModel):
method: Literal['GET', 'POST']
query_id: str
endpoint: str
features: dict[str, Any] | None
features: dict[str, bool] | None

@computed_field
@property
Expand Down
7 changes: 6 additions & 1 deletion server/app/utils/TwitterGraphQLAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ async def updateEndpointInfos(cls) -> None:
for switch in feature_switches:
if switch in feature_switch:
features[switch] = feature_switch[switch]['value'] == 'true'
else:
# ごく稀に featureSwitch にデフォルト値が書かれていない場合があるので、
# その場合は true をデフォルト値とする
features[switch] = True
if not features:
features = None

Expand Down Expand Up @@ -522,7 +526,8 @@ async def invokeGraphQLAPI(self,

# HTTP ステータスコードが 200 系以外の場合
if not (200 <= response.status_code < 300):
logging.error(f'[TwitterGraphQLAPI] Failed to invoke GraphQL API (HTTP {response.status_code})')
logging.error(f'[TwitterGraphQLAPI] Failed to invoke GraphQL API (HTTP Error {response.status_code})')
logging.error(f'[TwitterGraphQLAPI] Response: {response.text}')
return error_message_prefix + f'Twitter API から HTTP {response.status_code} エラーが返されました。'

# JSON でないレスポンスが返ってきた場合
Expand Down

0 comments on commit 04b0ac0

Please sign in to comment.