Skip to content

Commit d682440

Browse files
committed
fix an error in headers
1 parent 5d4d936 commit d682440

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

twitchio/ext/eventsub/models.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ def __init__(self, frame: dict):
121121
self.message_type: Literal["notification", "revocation", "reconnect", "session_keepalive"] = meta["message_type"]
122122
self.message_retry: int = 0 # don't make breaking changes with the Header class
123123
self.signature: str = ""
124-
self.subscription_type: str = frame["payload"]["subscription"]["type"]
125-
self.subscription_version: str = frame["payload"]["subscription"]["version"]
124+
self.subscription_type: Optional[str]
125+
self.subscription_version: Optional[str]
126+
if frame["payload"]:
127+
self.subscription_type = frame["payload"]["subscription"]["type"]
128+
self.subscription_version = frame["payload"]["subscription"]["version"]
129+
else:
130+
self.subscription_type = None
131+
self.subscription_version = None
126132

127133

128134
class BaseEvent:
@@ -157,16 +163,19 @@ def __init__(self, client: Union[EventSubClient, EventSubWSClient], _data: Union
157163
data = _data
158164

159165
self.headers: Union[Headers, WebsocketHeaders]
160-
self.subscription: Subscription
161166

162167
if request:
163168
data: dict = _loads(_data)
164169
self.headers = Headers(request)
165-
self.subscription = Subscription(data["subscription"])
170+
self.subscription: Subscription = Subscription(data["subscription"])
166171
self.setup(data)
167172
else:
168173
self.headers = WebsocketHeaders(data)
169-
self.subscription = Subscription(data["payload"]["subscription"])
174+
self.subscription: Optional[Subscription]
175+
if data["payload"]:
176+
self.subscription = Subscription(data["payload"]["subscription"])
177+
else:
178+
self.subscription = None
170179
self.setup(data["payload"])
171180

172181

twitchio/ext/eventsub/websocket.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ async def pump(self) -> None:
180180
await self.connect()
181181
return
182182

183+
except Exception as e:
184+
logger.error("Exception in the pump function!", exc_info=e)
185+
183186
def parse_frame(self, frame: dict) -> _messages:
184187
type_: str = frame["metadata"]["message_type"]
185188
return _message_types[type_](self, frame, None)

0 commit comments

Comments
 (0)