refactor(api): Enhance error handling in BasePluginManager (#17887)

This commit is contained in:
QuantumGhost 2025-04-11 17:32:20 +08:00 committed by GitHub
parent 8e6f6d64a4
commit 4ef297bf38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 3 deletions

View File

@ -170,13 +170,16 @@ class BasePluginManager:
for line in self._stream_request(method, path, params, headers, data, files): for line in self._stream_request(method, path, params, headers, data, files):
try: try:
rep = PluginDaemonBasicResponse[type].model_validate_json(line) # type: ignore rep = PluginDaemonBasicResponse[type].model_validate_json(line) # type: ignore
except Exception: except (ValueError, TypeError):
# TODO modify this when line_data has code and message # TODO modify this when line_data has code and message
try: try:
line_data = json.loads(line) line_data = json.loads(line)
raise ValueError(line_data["error"]) except (ValueError, TypeError):
except Exception:
raise ValueError(line) raise ValueError(line)
# If the dictionary contains the `error` key, use its value as the argument
# for `ValueError`.
# Otherwise, use the `line` to provide better contextual information about the error.
raise ValueError(line_data.get("error", line))
if rep.code != 0: if rep.code != 0:
if rep.code == -500: if rep.code == -500: