1010from twitchio import PartialUser , Unauthorized , HTTPException
1111
1212if TYPE_CHECKING :
13+ from typing_extensions import Literal
1314 from twitchio import Client
1415
1516logger = logging .getLogger ("twitchio.ext.eventsub.ws" )
@@ -32,7 +33,7 @@ def __init__(self, event_type: Tuple[str, int, Type[models.EventData]], conditio
3233 self .token = token
3334 self .subscription_id : Optional [str ] = None
3435 self .cost : Optional [int ] = None
35- self .created : asyncio .Future [Tuple [bool , int ]] | None = asyncio .Future ()
36+ self .created : asyncio .Future [Tuple [Literal [ False ] , int ] | Tuple [ Literal [ True ], None ]] | None = asyncio .Future ()
3637
3738
3839_T = TypeVar ("_T" )
@@ -117,18 +118,25 @@ async def _subscribe(self, obj: _Subscription) -> dict | None:
117118 try :
118119 resp = await self ._http .create_websocket_subscription (obj .event , obj .condition , self ._session_id , obj .token )
119120 except HTTPException as e :
120- assert obj .created
121- obj .created .set_result ((False , e .status )) # type: ignore
121+ if obj .created :
122+ obj .created .set_result ((False , e .status ))
123+
124+ else :
125+ logger .error (
126+ "An error (%s %s) occurred while attempting to resubscribe to an event on reconnect: %s" ,
127+ e .status ,
128+ e .reason ,
129+ e .message ,
130+ )
131+
122132 return None
123133
124- else :
125- assert obj .created
126- obj .created .set_result ((True , None )) # type: ignore
134+ if obj .created :
135+ obj .created .set_result ((True , None ))
127136
128137 data = resp ["data" ][0 ]
129- cost = data ["cost" ]
130138 self .remaining_slots = resp ["max_total_cost" ] - resp ["total_cost" ]
131- obj .cost = cost
139+ obj .cost = data [ " cost" ]
132140
133141 return data
134142
0 commit comments