+-+-+ +-+ +-+-+-+-+
|G|O| |4| |H|I|V|E|
+-+-+ +-+ +-+-+-+-+

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

Missing error handling in WebSockets code

BY: @nafestw | CREATED: April 18, 2018, 6:34 p.m. | VOTES: 5 | PAYOUT: $43.76 | [ VOTE ]

The code for sending requests via WebSockets misses proper error handling, such that problems cannot be handled in user code.

How to reproduce

const steem = require("steem");
steem.api.setOptions({ url: "wss://steemd.privex.io" });
steem.api.getAccounts(["nafestw"], (err, resp) => {
  console.log("Callback is called. err = " + err);
});

Expected behavior

The callback is called with err set to an object describing the error, which should be printed to the console.

Actual behavior

The following error occurs and the callback function is not called.

Unhandled rejection Error: getaddrinfo ENOTFOUND steemd.privex.io steemd.privex.io:443
    at errnoException (dns.js:55:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:26)

Suggested Fix

Adding the missing .catch in src/api/transports/ws.js should fix the problem:

diff --git a/src/api/transports/ws.js b/src/api/transports/ws.js
index 863ec4f..814d701 100644
--- a/src/api/transports/ws.js
+++ b/src/api/transports/ws.js
@@ -94,7 +94,7 @@ export default class WsTransport extends Transport {
       this._requests.set(_request.message.id, _request);
       this.ws.send(JSON.stringify(_request.message));
       return deferral;
-    });
+    }).catch(err => callback(err, null));
   }

   onError(error) {

Posted on Utopian.io - Rewarding Open Source Contributors

TAGS: [ #utopian-io ] [ #steemjs ]

Replies

@justyy | April 21, 2018, 12:51 a.m. | Votes: 5 | [ VOTE ]

Thank you for the report.

Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

@utopian-io | April 21, 2018, 1:01 a.m. | Votes: 0 | [ VOTE ]

Hey @nafestw! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

@devske | March 12, 2020, 4:59 p.m. | Votes: 1 | [ VOTE ]

Yeah was running into this problem a couple of times myself and forgot to fix the module after updating it or reinstalling it. So i have repackaged the module on npm with the fix in it.

npm install steemjs-fixed --save

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>