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 Nov 22, 2017
1 parent 5308f1c commit 73e579a
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 @@ -383,7 +385,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 73e579a

Please # to comment.