File tree Expand file tree Collapse file tree 5 files changed +20
-23
lines changed
Expand file tree Collapse file tree 5 files changed +20
-23
lines changed Original file line number Diff line number Diff line change @@ -235,10 +235,6 @@ class APIClient {
235235 Message . error ( `${ template } \nこのリソースにアクセスする権限がありません。` ) ;
236236 return ;
237237 }
238- case 'Chrome or Brave is not installed on this machine.' : {
239- Message . error ( 'ヘッドレスブラウザの起動に必要な Chrome または Brave が KonomiTV サーバーにインストールされていません。' ) ;
240- return ;
241- }
242238 default : {
243239 if ( Array . isArray ( error_response . data . detail ) ) {
244240 // バリデーションエラーが発生した場合
Original file line number Diff line number Diff line change @@ -77,12 +77,8 @@ class Twitter {
7777 Message . error ( 'Twitter アカウント情報の取得に失敗しました。' ) ;
7878 break ;
7979 }
80- case 'Chrome or Brave is not installed on this machine.' : {
81- Message . error ( 'ヘッドレスブラウザの起動に必要な Chrome または Brave が KonomiTV サーバーにインストールされていません。' ) ;
82- break ;
83- }
8480 default : {
85- APIClient . showGenericError ( response , 'Twitter アカウントとの連携に失敗しました。再度お試しください。 ' ) ;
81+ APIClient . showGenericError ( response , 'Twitter アカウントとの連携に失敗しました。' ) ;
8682 break ;
8783 }
8884 }
@@ -160,13 +156,6 @@ class Twitter {
160156 // エラー処理 (API リクエスト自体に失敗した場合)
161157 // このエンドポイントのみ、Message (SnackBar) では通知せず、通知をプレイヤー側に委ねる必要がある
162158 if ( response . type === 'error' ) {
163- if ( typeof response . data . detail === 'string' &&
164- response . data . detail === 'Chrome or Brave is not installed on this machine.' ) {
165- return {
166- message : 'ヘッドレスブラウザの起動に必要な Chrome または Brave が KonomiTV サーバーにインストールされていません。' ,
167- is_error : true ,
168- } ;
169- }
170159 if ( typeof response . data . detail === 'string' ) {
171160 if ( Number . isNaN ( response . status ) ) {
172161 // HTTP リクエスト自体が失敗し、HTTP ステータスコードが取得できなかった場合
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ async def TwitterCookieAuthAPI(
154154 logging .error (f'[TwitterRouter][TwitterCookieAuthAPI] Failed to get user information: { viewer_result .detail } ' )
155155 raise HTTPException (
156156 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
157- detail = viewer_result .detail ,
157+ detail = viewer_result .detail , # エラーメッセージをそのまま返す
158158 )
159159
160160 # viewer_result が TweetUser の場合のみ処理を続行
Original file line number Diff line number Diff line change 1212from app .models .TwitterAccount import TwitterAccount
1313from app .utils .TwitterScrapeBrowser import (
1414 BrowserBinaryNotFoundError ,
15+ BrowserConnectionFailedError ,
1516 TwitterScrapeBrowser ,
1617)
1718
@@ -263,10 +264,9 @@ async def invokeGraphQLAPI(
263264 if self ._browser .is_setup_complete is not True :
264265 try :
265266 await self ._browser .setup ()
266- except BrowserBinaryNotFoundError as ex :
267- # Chrome / Brave 未導入時は UI に案内できるよう固定のエラーメッセージを返す
268- logging .error (f'{ self .log_prefix } Chrome or Brave is not installed on this machine:' , exc_info = ex )
269- return 'Chrome or Brave is not installed on this machine.'
267+ except (BrowserBinaryNotFoundError , BrowserConnectionFailedError ) as ex :
268+ # Chrome / Brave 未導入時やブラウザ起動失敗時は、日本語のエラーメッセージをそのまま返す
269+ return str (ex )
270270
271271 # TwitterScrapeBrowser 経由で GraphQL API に HTTP リクエストを送信
272272 browser = self ._browser
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ class BrowserBinaryNotFoundError(RuntimeError):
1414 Chrome / Brave の実行ファイルが検出できず、Zendriver がブラウザを起動できない場合に送出される例外
1515 """
1616
17+ class BrowserConnectionFailedError (RuntimeError ):
18+ """
19+ Chrome / Brave はおそらく起動できたが、ブラウザインスタンスへの接続に失敗した場合に送出される例外
20+ """
21+
1722
1823class TwitterScrapeBrowser :
1924 """
@@ -103,8 +108,15 @@ async def setup(self) -> None:
103108 ]
104109 )
105110 except FileNotFoundError as ex :
106- logging .error (f'{ self .log_prefix } Chrome or Brave is not installed.' , exc_info = ex )
107- raise BrowserBinaryNotFoundError ('Chrome or Brave is not installed on this machine.' ) from ex
111+ logging .error (f'{ self .log_prefix } Chrome or Brave is not installed on this machine:' , exc_info = ex )
112+ raise BrowserBinaryNotFoundError ('ヘッドレスブラウザの起動に必要な Chrome または Brave が KonomiTV サーバーにインストールされていません。' ) from ex
113+ except Exception as ex :
114+ if 'Failed to connect to browser' in str (ex ):
115+ logging .error (f'{ self .log_prefix } Browser connection failed. Please check if Chrome or Brave is installed:' , exc_info = ex )
116+ raise BrowserConnectionFailedError ('ヘッドレスブラウザとの接続に失敗しました。Chrome または Brave が KonomiTV サーバーにインストールされているかどうかを確認してください。' ) from ex
117+ else :
118+ logging .error (f'{ self .log_prefix } Error starting browser:' , exc_info = ex )
119+ raise ex
108120 logging .info (f'{ self .log_prefix } Browser started.' )
109121
110122 # まず空のタブを開く
You can’t perform that action at this time.
0 commit comments