Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit d4c8814

Browse files
committed
listener: add back support for TIMEOUT special event
This reverts commit be3b868. Signed-off-by: Sumner Evans <me@sumnerevans.com>
1 parent 5d53da6 commit d4c8814

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.5.5
2+
3+
* Add back support for the `TIMEOUT` special event. All other errors still need
4+
to be handled by API consumers.
5+
16
# v0.5.4
27

38
* Fix the `__license__` property in the package.

linkedin_messaging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .linkedin import ChallengeException, LinkedInMessaging
55

66
__title__ = "linkedin_messaging"
7-
__version__ = "0.5.4"
7+
__version__ = "0.5.5"
88
__description__ = "An unofficial API for interacting with LinkedIn Messaging"
99

1010
__license__ = "Apache License 2.0"

linkedin_messaging/linkedin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,16 @@ def add_event_listener(
498498
payload_key: str,
499499
fn: Union[
500500
Callable[[RealTimeEventStreamEvent], Awaitable[None]],
501+
Callable[[asyncio.exceptions.TimeoutError], Awaitable[None]],
501502
Callable[[Exception], Awaitable[None]],
502503
],
503504
):
504505
"""
505-
There is one special event type:
506+
There are two special event types:
506507
507508
* ``ALL_EVENTS`` - an event fired on every event, and which contains the entirety of the
508509
raw event payload
510+
* ``TIMEOUT`` - an event fired if the event listener connection times out
509511
"""
510512
self.event_listeners[payload_key].append(fn)
511513

@@ -561,6 +563,14 @@ async def start_listener(self):
561563
while True:
562564
try:
563565
await self._listen_to_event_stream()
566+
except asyncio.exceptions.TimeoutError as te:
567+
# Special handling for TIMEOUT handler.
568+
if timeout_handlers := self.event_listeners.get("TIMEOUT"):
569+
for handler in timeout_handlers:
570+
try:
571+
await handler(te)
572+
except Exception:
573+
logging.exception(f"Handler {handler} failed to handle {te}")
564574
except Exception as e:
565575
logging.exception(f"Got exception in listener: {e}")
566576
raise

0 commit comments

Comments
 (0)