2424 InvalidParamsError ,
2525 InvalidRequestError ,
2626 JSONParseError ,
27+ JSONRPCError ,
2728 MethodNotFoundError ,
2829)
2930from a2a .server .request_handlers .jsonrpc_handler import JSONRPCHandler
4950 PREV_AGENT_CARD_WELL_KNOWN_PATH ,
5051)
5152from a2a .utils .errors import (
53+ A2AException ,
5254 MethodNotImplementedError ,
5355 UnsupportedOperationError ,
5456)
@@ -225,7 +227,9 @@ def __init__( # noqa: PLR0913
225227 self ._max_content_length = max_content_length
226228
227229 def _generate_error_response (
228- self , request_id : str | int | None , error : Exception
230+ self ,
231+ request_id : str | int | None ,
232+ error : Exception | JSONRPCError | A2AException ,
229233 ) -> JSONResponse :
230234 """Creates a Starlette JSONResponse for a JSON-RPC error.
231235
@@ -238,6 +242,9 @@ def _generate_error_response(
238242 Returns:
239243 A `JSONResponse` object formatted as a JSON-RPC error response.
240244 """
245+ if not isinstance (error , (A2AException , JSONRPCError )):
246+ error = InternalError (message = str (error ))
247+
241248 response_data = build_error_response (request_id , error )
242249 error_info = response_data .get ('error' , {})
243250 code = error_info .get ('code' )
0 commit comments