[Fix] Error Handling: Update setter methods to clarify None value handling and enhance authentication failure response policy.

This commit is contained in:
misyaguziya
2025-12-30 07:52:08 +09:00
parent 588b95eebe
commit 01061cf98f
3 changed files with 12 additions and 6 deletions

View File

@@ -279,7 +279,7 @@ def SELECTED_TAB_NO(self, value):
```
各setterは以下のパターンを実装:
1. 型チェック (`isinstance`)**`None` 値は常に許可される** (値をクリアしたい場合への対応)
1. 型チェック (`isinstance`)`ManagedProperty` による型チェックは `None` を許容するが、個別 setter が数値変換などを行う場合は `None` を拒否するケースがある
2. 値の範囲・有効性チェック
3. 内部変数への代入
4. `saveConfig` 呼び出し(永続化対象の場合)
@@ -287,12 +287,12 @@ def SELECTED_TAB_NO(self, value):
#### 型チェックの詳細v3.3.0+
```python
# 型チェック実装None常に許可
# 型チェック実装:ManagedProperty 経由では None常に許可
if self.type_ is not None and value is not None and not isinstance(value, self.type_):
return # 無視する
```
この変更により、設定値をクリアNone に設定)する用途に対応。例えば認証失敗時に API キーを `None` に設定する場合に有効
この仕様は `ManagedProperty` を通じた型チェックに適用される。個別の setter で追加のバリデーションやキャストを行う場合、`None` は別途拒否されることがある
### メッセージフォーマット構造

View File

@@ -693,7 +693,13 @@ OSC Query 機能が無効になったことを通知。無効化された機能
- `config.AUTH_KEYS["DeepL_API"]` に保存
- `config.SELECTABLE_TRANSLATION_ENGINE_STATUS["DeepL_API"]` を True に
- `updateTranslationEngineAndEngineList()` を呼び出し
4. 認証失敗時: status 400 を返却
4. 認証失敗時 (status 400):
- レスポンス `data` フィールドは **常に None**(キーを返さない)
- `delDeeplAuthKey()` を呼び出してクリーンアップ
**認証失敗時の共通ポリシーPlamo/Gemini/OpenAI/DeepL/Groq/OpenRouter 共通)**
- レスポンス `data` はキーを含めず `None` を返す
- 対応する `del*AuthKey()` を呼び出し、保存済みキーとモデル選択をクリア
#### `delDeeplAuthKey(*args, **kwargs) -> dict`

View File

@@ -14,7 +14,7 @@ except Exception:
from translation_utils import loadTranslatePromptConfig
translation_lang = loadTranslationLanguages(path=".", force=True)
def _authentication_check(api_key: str, base_url: str | None = None) -> bool:
def _authentication_check(api_key: str) -> bool:
"""Check if the provided API key is valid by attempting to list models.
"""
@@ -94,7 +94,7 @@ class OpenRouterClient:
return self.api_key
def setAuthKey(self, api_key: str) -> bool:
result = _authentication_check(api_key, self.base_url)
result = _authentication_check(api_key)
if result:
self.api_key = api_key
return result