chore: enhance error message when handling PluginInvokeError (#22908)
This commit is contained in:
parent
45cebf09b0
commit
206bc4b36d
3 changed files with 47 additions and 4 deletions
|
|
@ -1,3 +1,8 @@
|
|||
from collections.abc import Mapping
|
||||
|
||||
from pydantic import TypeAdapter
|
||||
|
||||
|
||||
class PluginDaemonError(Exception):
|
||||
"""Base class for all plugin daemon errors."""
|
||||
|
||||
|
|
@ -36,6 +41,21 @@ class PluginDaemonBadRequestError(PluginDaemonClientSideError):
|
|||
class PluginInvokeError(PluginDaemonClientSideError):
|
||||
description: str = "Invoke Error"
|
||||
|
||||
def _get_error_object(self) -> Mapping:
|
||||
try:
|
||||
return TypeAdapter(Mapping).validate_json(self.description)
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
def get_error_type(self) -> str:
|
||||
return self._get_error_object().get("error_type", "unknown")
|
||||
|
||||
def get_error_message(self) -> str:
|
||||
try:
|
||||
return self._get_error_object().get("message", "unknown")
|
||||
except Exception:
|
||||
return self.description
|
||||
|
||||
|
||||
class PluginUniqueIdentifierError(PluginDaemonClientSideError):
|
||||
description: str = "Unique Identifier Error"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue