[Fix] Error Handling: Update setter methods to clarify None value handling and enhance authentication failure response policy.
This commit is contained in:
@@ -279,7 +279,7 @@ def SELECTED_TAB_NO(self, value):
|
|||||||
```
|
```
|
||||||
|
|
||||||
各setterは以下のパターンを実装:
|
各setterは以下のパターンを実装:
|
||||||
1. 型チェック (`isinstance`):**`None` 値は常に許可される** (値をクリアしたい場合への対応)
|
1. 型チェック (`isinstance`):`ManagedProperty` による型チェックは `None` を許容するが、個別 setter が数値変換などを行う場合は `None` を拒否するケースがある
|
||||||
2. 値の範囲・有効性チェック
|
2. 値の範囲・有効性チェック
|
||||||
3. 内部変数への代入
|
3. 内部変数への代入
|
||||||
4. `saveConfig` 呼び出し(永続化対象の場合)
|
4. `saveConfig` 呼び出し(永続化対象の場合)
|
||||||
@@ -287,12 +287,12 @@ def SELECTED_TAB_NO(self, value):
|
|||||||
#### 型チェックの詳細(v3.3.0+)
|
#### 型チェックの詳細(v3.3.0+)
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# 型チェック実装:Noneは常に許可
|
# 型チェック実装:ManagedProperty 経由では None を常に許可
|
||||||
if self.type_ is not None and value is not None and not isinstance(value, self.type_):
|
if self.type_ is not None and value is not None and not isinstance(value, self.type_):
|
||||||
return # 無視する
|
return # 無視する
|
||||||
```
|
```
|
||||||
|
|
||||||
この変更により、設定値をクリア(None に設定)する用途に対応。例えば認証失敗時に API キーを `None` に設定する場合に有効。
|
この仕様は `ManagedProperty` を通じた型チェックに適用される。個別の setter で追加のバリデーションやキャストを行う場合、`None` は別途拒否されることがある。
|
||||||
|
|
||||||
### メッセージフォーマット構造
|
### メッセージフォーマット構造
|
||||||
|
|
||||||
|
|||||||
@@ -693,7 +693,13 @@ OSC Query 機能が無効になったことを通知。無効化された機能
|
|||||||
- `config.AUTH_KEYS["DeepL_API"]` に保存
|
- `config.AUTH_KEYS["DeepL_API"]` に保存
|
||||||
- `config.SELECTABLE_TRANSLATION_ENGINE_STATUS["DeepL_API"]` を True に
|
- `config.SELECTABLE_TRANSLATION_ENGINE_STATUS["DeepL_API"]` を True に
|
||||||
- `updateTranslationEngineAndEngineList()` を呼び出し
|
- `updateTranslationEngineAndEngineList()` を呼び出し
|
||||||
4. 認証失敗時: status 400 を返却
|
4. 認証失敗時 (status 400):
|
||||||
|
- レスポンス `data` フィールドは **常に None**(キーを返さない)
|
||||||
|
- `delDeeplAuthKey()` を呼び出してクリーンアップ
|
||||||
|
|
||||||
|
**認証失敗時の共通ポリシー(Plamo/Gemini/OpenAI/DeepL/Groq/OpenRouter 共通)**
|
||||||
|
- レスポンス `data` はキーを含めず `None` を返す
|
||||||
|
- 対応する `del*AuthKey()` を呼び出し、保存済みキーとモデル選択をクリア
|
||||||
|
|
||||||
#### `delDeeplAuthKey(*args, **kwargs) -> dict`
|
#### `delDeeplAuthKey(*args, **kwargs) -> dict`
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ except Exception:
|
|||||||
from translation_utils import loadTranslatePromptConfig
|
from translation_utils import loadTranslatePromptConfig
|
||||||
translation_lang = loadTranslationLanguages(path=".", force=True)
|
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.
|
"""Check if the provided API key is valid by attempting to list models.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ class OpenRouterClient:
|
|||||||
return self.api_key
|
return self.api_key
|
||||||
|
|
||||||
def setAuthKey(self, api_key: str) -> bool:
|
def setAuthKey(self, api_key: str) -> bool:
|
||||||
result = _authentication_check(api_key, self.base_url)
|
result = _authentication_check(api_key)
|
||||||
if result:
|
if result:
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user