From 76d761a4e3d20f79857cc053971932219ff23d48 Mon Sep 17 00:00:00 2001 From: sandwich <299465+dskvr@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:06:16 +0000 Subject: [PATCH] better edge case handling --- .../nocap/adapters/default/EveryAdapterDefault/package.json | 4 ++-- .../nocap/adapters/default/WebsocketAdapterDefault/index.js | 6 ++++-- .../adapters/default/WebsocketAdapterDefault/package.json | 2 +- packages/nocap/package.json | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/nocap/adapters/default/EveryAdapterDefault/package.json b/packages/nocap/adapters/default/EveryAdapterDefault/package.json index 7da1d0bd..2cc44695 100644 --- a/packages/nocap/adapters/default/EveryAdapterDefault/package.json +++ b/packages/nocap/adapters/default/EveryAdapterDefault/package.json @@ -1,6 +1,6 @@ { "name": "@nostrwatch/nocap-every-adapter-default", - "version": "1.0.4", + "version": "1.0.5", "type": "module", "main": "index.js", "license": "MIT", @@ -9,6 +9,6 @@ "@nostrwatch/nocap-geo-adapter-default": "^1.0.0", "@nostrwatch/nocap-info-adapter-default": "^1.0.0", "@nostrwatch/nocap-ssl-adapter-default": "^1.0.1", - "@nostrwatch/nocap-websocket-adapter-default": "^1.0.2" + "@nostrwatch/nocap-websocket-adapter-default": "^1.0.3" } } diff --git a/packages/nocap/adapters/default/WebsocketAdapterDefault/index.js b/packages/nocap/adapters/default/WebsocketAdapterDefault/index.js index ca018a0d..47d2b2ec 100644 --- a/packages/nocap/adapters/default/WebsocketAdapterDefault/index.js +++ b/packages/nocap/adapters/default/WebsocketAdapterDefault/index.js @@ -81,13 +81,15 @@ class WebsocketAdapterDefault { * @returns null */ handle_nostr_event(buffer){ + let ev try{ - const ev = JSON.parse(buffer.toString()) + ev = JSON.parse(buffer.toString()) } catch(e){ this.$.logger.err(`${this.$.url} responded with invalid JSON: ${e}`) - return this.$.on_error(e) + return } + if(!ev || !(ev instanceof Array) || !ev.length) return if(ev[0] === 'EVENT') { if(this.$.subid('read') === ev[1]) this.$.on_event(ev[1], ev[2]) diff --git a/packages/nocap/adapters/default/WebsocketAdapterDefault/package.json b/packages/nocap/adapters/default/WebsocketAdapterDefault/package.json index 79c52409..af73b3ed 100644 --- a/packages/nocap/adapters/default/WebsocketAdapterDefault/package.json +++ b/packages/nocap/adapters/default/WebsocketAdapterDefault/package.json @@ -1,6 +1,6 @@ { "name": "@nostrwatch/nocap-websocket-adapter-default", - "version": "1.0.2", + "version": "1.0.3", "type": "module", "main": "index.js", "license": "MIT", diff --git a/packages/nocap/package.json b/packages/nocap/package.json index 7d8c5eb6..6c72cc8b 100644 --- a/packages/nocap/package.json +++ b/packages/nocap/package.json @@ -1,6 +1,6 @@ { "name": "@nostrwatch/nocap", - "version": "0.1.6", + "version": "0.1.7", "main": "src/index.js", "type": "module", "license": "MIT", @@ -10,7 +10,7 @@ }, "dependencies": { "@nostrwatch/logger": "^0.0.1", - "@nostrwatch/nocap-every-adapter-default": "^1.0.4", + "@nostrwatch/nocap-every-adapter-default": "^1.0.5", "@nostrwatch/utils": "^0.0.1", "fetch-h2": "3.0.2", "get-ssl-certificate": "2.3.3",