diff --git a/application/source/data/datasource/websocket.mjs b/application/source/data/datasource/websocket.mjs index 099bf1363c6bb42f00be17a0ec3ceed50383b925..146be1635f6d6ad0f295055703a59af7524cbadb 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');