Skip to content

Commit

Permalink
[refactor] Add some checks to prevent usage of undefined properties (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Tazelaar authored and darrachequesne committed Feb 18, 2018
1 parent 1a685c0 commit 8d0ce5f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ function sendErrorMessage (req, res, code) {
} else {
headers['Access-Control-Allow-Origin'] = '*';
}
res.writeHead(400, headers);
res.end(JSON.stringify({
code: code,
message: Server.errorMessages[code]
}));
if (res !== undefined) {
res.writeHead(400, headers);
res.end(JSON.stringify({
code: code,
message: Server.errorMessages[code]
}));
}
}

/**
Expand Down Expand Up @@ -379,7 +381,7 @@ Server.prototype.handleUpgrade = function (req, socket, upgradeHead) {
Server.prototype.onWebSocket = function (req, socket) {
socket.on('error', onUpgradeError);

if (!transports[req._query.transport].prototype.handlesUpgrades) {
if (transports[req._query.transport] !== undefined && !transports[req._query.transport].prototype.handlesUpgrades) {
debug('transport doesnt handle upgraded requests');
socket.close();
return;
Expand Down

0 comments on commit 8d0ce5f

Please sign in to comment.