Skip to content

Commit

Permalink
server: prevent getaddrinfo crash.
Browse files Browse the repository at this point in the history
When there is no internet connection and the client tries to connect to
server, it throws a getaddrinfo error.

Error: getaddrinfo ENOTFOUND www.tmijs.org
at errnoException (dns.js:44:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)
  • Loading branch information
Schmoopiie committed Jul 10, 2015
1 parent 19f9157 commit e7a86b7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,32 @@ function getRandomServer(serverType, callback) {

// Update the server list using our API with CORS support..
function updateServers(callback) {
http.get({
var req = http.get({
host: "www.tmijs.org",
path: "/api/servers/",
withCredentials: false,
protocol:"http:"
}, function(res) {
var body = "";
res.on('data', function(buffer) {
res.on("data", function(buffer) {
body += buffer;
});
res.on('end', function() {
res.on("end", function() {
if (res.statusCode === 200) {
chat_servers = JSON.parse(body)["chat_servers"];
event_servers = JSON.parse(body)["event_servers"];
group_servers = JSON.parse(body)["group_servers"];
}
return callback(null);
});
res.on('error', function() {
res.on("error", function() {
return callback(null);
});
});

req.on("error", function() {
return callback(null);
});
}

// Detects if the server is accepting WebSocket connections..
Expand Down

0 comments on commit e7a86b7

Please sign in to comment.