forked from a2aproject/a2a-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
82 lines (68 loc) · 2.5 KB
/
errors.py
File metadata and controls
82 lines (68 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Custom exceptions for A2A server-side errors."""
from a2a.types import (
AuthenticatedExtendedCardNotConfiguredError,
ContentTypeNotSupportedError,
InternalError,
InvalidAgentResponseError,
InvalidParamsError,
InvalidRequestError,
JSONParseError,
JSONRPCError,
MethodNotFoundError,
PushNotificationNotSupportedError,
TaskNotCancelableError,
TaskNotFoundError,
UnsupportedOperationError,
)
class A2AServerError(Exception):
"""Base exception for A2A Server errors."""
class MethodNotImplementedError(A2AServerError):
"""Exception raised for methods that are not implemented by the server handler."""
def __init__(
self, message: str = 'This method is not implemented by the server'
):
"""Initializes the MethodNotImplementedError.
Args:
message: A descriptive error message.
"""
self.message = message
super().__init__(f'Not Implemented operation Error: {message}')
class ServerError(Exception):
"""Wrapper exception for A2A or JSON-RPC errors originating from the server's logic.
This exception is used internally by request handlers and other server components
to signal a specific error that should be formatted as a JSON-RPC error response.
"""
def __init__(
self,
error: (
JSONRPCError
| JSONParseError
| InvalidRequestError
| MethodNotFoundError
| InvalidParamsError
| InternalError
| TaskNotFoundError
| TaskNotCancelableError
| PushNotificationNotSupportedError
| UnsupportedOperationError
| ContentTypeNotSupportedError
| InvalidAgentResponseError
| AuthenticatedExtendedCardNotConfiguredError
| None
),
):
"""Initializes the ServerError.
Args:
error: The specific A2A or JSON-RPC error model instance.
"""
self.error = error
def __str__(self) -> str:
"""Returns a readable representation of the internal Pydantic error."""
if self.error is None:
return 'None'
if self.error.message is None:
return self.error.__class__.__name__
return self.error.message
def __repr__(self) -> str:
"""Returns an unambiguous representation for developers showing how the ServerError was constructed with the internal Pydantic error."""
return f'{self.__class__.__name__}({self.error!r})'