Skip to content

Commit c41fd93

Browse files
authored
refactor: throw PushNotificationNotSupportedError instead of a generic one (#903)
See https://a2a-protocol.org/latest/specification/#332-error-handling.
1 parent 6fa139e commit c41fd93

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from a2a.utils.errors import (
5050
InternalError,
5151
InvalidParamsError,
52+
PushNotificationNotSupportedError,
5253
TaskNotCancelableError,
5354
TaskNotFoundError,
5455
UnsupportedOperationError,
@@ -493,7 +494,7 @@ async def on_create_task_push_notification_config(
493494
Requires a `PushNotifier` to be configured.
494495
"""
495496
if not self._push_config_store:
496-
raise UnsupportedOperationError
497+
raise PushNotificationNotSupportedError
497498

498499
task_id = params.task_id
499500
task: Task | None = await self.task_store.get(task_id, context)
@@ -519,7 +520,7 @@ async def on_get_task_push_notification_config(
519520
Requires a `PushConfigStore` to be configured.
520521
"""
521522
if not self._push_config_store:
522-
raise UnsupportedOperationError
523+
raise PushNotificationNotSupportedError
523524

524525
task_id = params.task_id
525526
config_id = params.id
@@ -594,7 +595,7 @@ async def on_list_task_push_notification_configs(
594595
Requires a `PushConfigStore` to be configured.
595596
"""
596597
if not self._push_config_store:
597-
raise UnsupportedOperationError
598+
raise PushNotificationNotSupportedError
598599

599600
task_id = params.task_id
600601
task: Task | None = await self.task_store.get(task_id, context)
@@ -620,7 +621,7 @@ async def on_delete_task_push_notification_config(
620621
Requires a `PushConfigStore` to be configured.
621622
"""
622623
if not self._push_config_store:
623-
raise UnsupportedOperationError
624+
raise PushNotificationNotSupportedError
624625

625626
task_id = params.task_id
626627
config_id = params.id

tests/server/request_handlers/test_default_request_handler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from a2a.types import (
3939
InternalError,
4040
InvalidParamsError,
41+
PushNotificationNotSupportedError,
4142
TaskNotCancelableError,
4243
TaskNotFoundError,
4344
UnsupportedOperationError,
@@ -1991,7 +1992,7 @@ async def test_set_task_push_notification_config_no_notifier():
19911992
url='http://example.com',
19921993
)
19931994

1994-
with pytest.raises(UnsupportedOperationError):
1995+
with pytest.raises(PushNotificationNotSupportedError):
19951996
await request_handler.on_create_task_push_notification_config(
19961997
params, create_server_call_context()
19971998
)
@@ -2038,7 +2039,7 @@ async def test_get_task_push_notification_config_no_store():
20382039
id='task_push_notification_config',
20392040
)
20402041

2041-
with pytest.raises(UnsupportedOperationError):
2042+
with pytest.raises(PushNotificationNotSupportedError):
20422043
await request_handler.on_get_task_push_notification_config(
20432044
params, create_server_call_context()
20442045
)
@@ -2269,7 +2270,7 @@ async def test_list_task_push_notification_config_no_store():
22692270
)
22702271
params = ListTaskPushNotificationConfigsRequest(task_id='task1')
22712272

2272-
with pytest.raises(UnsupportedOperationError):
2273+
with pytest.raises(PushNotificationNotSupportedError):
22732274
await request_handler.on_list_task_push_notification_configs(
22742275
params, create_server_call_context()
22752276
)
@@ -2414,11 +2415,10 @@ async def test_delete_task_push_notification_config_no_store():
24142415
task_id='task1', id='config1'
24152416
)
24162417

2417-
with pytest.raises(UnsupportedOperationError) as exc_info:
2418+
with pytest.raises(PushNotificationNotSupportedError):
24182419
await request_handler.on_delete_task_push_notification_config(
24192420
params, create_server_call_context()
24202421
)
2421-
assert isinstance(exc_info.value, UnsupportedOperationError)
24222422

24232423

24242424
@pytest.mark.asyncio

0 commit comments

Comments
 (0)