Published: 18 Apr 2018 › Updated: 18 Apr 2018

Missing error handling in WebSockets code
The code for sending requests via WebSockets misses proper error handling, such that problems cannot be handled in user code.
How to reproduce
- Should be reproducible on any PC that runs Node.js
- Disconnect from the Internet
- Run the following code with Node.js
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
Leave Missing error handling in WebSockets code to:
Read more #utopian-io posts
Best Posts From nafestw
We have not curated any of nafestw's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From nafestw
- Welcome to STEEM @qiortate12, @qiortate13, @qiortate14, @qiortate15, @qiortate16, @qiortate17, @qiortate18, @qiortate19, and @qiortate20 [which are totally not abusing @steem's delegations for new users]
- Celebrating my first 100 STEEM days with free upvotes
- More than 500.000 SP undelegated from @dmania in the last 24 hours
- DeepSteem - Increased robustness and some minor features
- Missing error handling in WebSockets code
- DeepSteem - A dashboard for the STEEM blockchain
- DeepSteem now shows the cumulative voting value of all your followers
- My current side project: DeepSteem - a dashboard for STEEM
- A good time to use bid bots (SBD demand already rising)
- Steem.js api comes with functions that return Promises
- Estimate author payouts with Steem.js
- SBD payouts back to 100%
- Handicraft made by my kids
- Last weeks biggest transfers of STEEM to Binance
- Why is the value of my vote declining? Is it really 0.0 SBD?
- A template for STEEM bots running on AWS Lambda
- Every programmer's dilemma
- Run a steem-js bot as AWS Lambda function
- MEAN Tutorial Part 4 - Frontend Navigation Bar
- MEAN Tutorial Part 3 - Registration and Authorization