From 936a53323bb551d5c999b55154ab80de5311d5bb Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Fri, 6 Jan 2023 16:39:35 +0100 Subject: [PATCH] fix: check socket state --- application/source/data/datasource/websocket.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/application/source/data/datasource/websocket.mjs b/application/source/data/datasource/websocket.mjs index 099bf1363..146be1635 100644 --- a/application/source/data/datasource/websocket.mjs +++ b/application/source/data/datasource/websocket.mjs @@ -231,14 +231,15 @@ class WebSocketDatasource extends Datasource { /** * @return {Promise} - * @throws {Error} the options does not contain a valid json definition - * @throws {Error} the data cannot be read - * @throws {TypeError} value is not an object */ read() { const self = this; let response; + if (self[connectionSymbol].socket||self[connectionSymbol].socket.readyState!==1) { + return Promise.reject('The connection is not established.'); + } + return new Promise((resolve, reject) => { if (self[receiveQueueSymbol].isEmpty()) { resolve(); @@ -290,6 +291,10 @@ class WebSocketDatasource extends Datasource { */ write() { const self = this; + + if (self[connectionSymbol].socket||self[connectionSymbol].socket.readyState!==1) { + return Promise.reject('The connection is not established.'); + } let obj = self.get(); let transformation = self.getOption('write.mapping.transformer'); -- GitLab