Improves Nostr message handling and error logging
Enhances the processing of Nostr messages by adding more robust error handling and logging, providing better insights into potential issues. Specifically: - Improves the checks on the websocket connection to log errors and debug information. - Implements more comprehensive error logging for failed product quantity checks. - Enhances logging and validation of EVENT messages to prevent potential errors. - Implements a more robust merchant lookup logic to avoid double processing of events. - Implements a more lenient time window for direct message subscriptions.
This commit is contained in:
parent
4856bf2f89
commit
429522adba
2 changed files with 49 additions and 35 deletions
|
|
@ -67,6 +67,7 @@ class NostrClient:
|
|||
async def get_event(self):
|
||||
value = await self.recieve_event_queue.get()
|
||||
if isinstance(value, ValueError):
|
||||
logger.error(f"[NOSTRMARKET] ❌ Queue returned error: {value}")
|
||||
raise value
|
||||
return value
|
||||
|
||||
|
|
@ -93,12 +94,6 @@ class NostrClient:
|
|||
self.subscription_id = "nostrmarket-" + urlsafe_short_hash()[:32]
|
||||
await self.send_req_queue.put(["REQ", self.subscription_id] + merchant_filters)
|
||||
|
||||
logger.info(
|
||||
f"[NOSTRMARKET DEBUG] Subscribing to events for: {len(public_keys)} keys. New subscription id: {self.subscription_id}"
|
||||
)
|
||||
logger.info(f"[NOSTRMARKET DEBUG] Subscription filters: {merchant_filters}")
|
||||
logger.info(f"[NOSTRMARKET DEBUG] Public keys: {public_keys}")
|
||||
|
||||
async def merchant_temp_subscription(self, pk, duration=10):
|
||||
dm_filters = self._filters_for_direct_messages([pk], 0)
|
||||
stall_filters = self._filters_for_stall_events([pk], 0)
|
||||
|
|
@ -179,20 +174,21 @@ class NostrClient:
|
|||
|
||||
def _ws_handlers(self):
|
||||
def on_open(_):
|
||||
logger.info("[NOSTRMARKET DEBUG] Connected to 'nostrclient' websocket")
|
||||
logger.debug("[NOSTRMARKET DEBUG] ✅ Connected to 'nostrclient' websocket successfully")
|
||||
|
||||
def on_message(_, message):
|
||||
logger.info(f"[NOSTRMARKET DEBUG] Received websocket message: {message[:200]}...")
|
||||
logger.debug(f"[NOSTRMARKET DEBUG] 📨 Received websocket message: {message[:200]}...")
|
||||
try:
|
||||
self.recieve_event_queue.put_nowait(message)
|
||||
logger.debug(f"[NOSTRMARKET DEBUG] 📤 Message queued successfully")
|
||||
except Exception as e:
|
||||
logger.error(f"[NOSTRMARKET DEBUG] ❌ Failed to queue message: {e}")
|
||||
logger.error(f"[NOSTRMARKET] ❌ Failed to queue message: {e}")
|
||||
|
||||
def on_error(_, error):
|
||||
logger.warning(f"[NOSTRMARKET DEBUG] ❌ Websocket error: {error}")
|
||||
logger.warning(f"[NOSTRMARKET] ❌ Websocket error: {error}")
|
||||
|
||||
def on_close(x, status_code, message):
|
||||
logger.warning(f"[NOSTRMARKET DEBUG] 🔌 Websocket closed: {x}: '{status_code}' '{message}'")
|
||||
logger.warning(f"[NOSTRMARKET] 🔌 Websocket closed: {x}: '{status_code}' '{message}'")
|
||||
# force re-subscribe
|
||||
self.recieve_event_queue.put_nowait(ValueError("Websocket close."))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue