refactor: handle request errors

This commit is contained in:
avwo
2019-10-09 23:59:06 +08:00
parent 794bb7a3d7
commit 5fdb4ccfc9
+3 -3
View File
@@ -27,7 +27,7 @@ function getSocket(options, callback) {
NPNProtocols: SUPPORTED_PROTOS
}, function(err, socket) {
if (err) {
return callback();
return callback(false, null, err);
}
var proto = socket.alpnProtocol || socket.npnProtocol;
callback(proto === 'h2', socket);
@@ -124,7 +124,7 @@ exports.request = function(req, res, callback) {
pendingList[name] = [[req, res, callback]];
}
}
getSocket(client ? null : options, function(isH2, socket) {
getSocket(client ? null : options, function(isH2, socket, err) {
client = client || (isH2 && getClient(req, socket, name));
var pendingItem = pendingList[name];
delete pendingList[name];
@@ -138,7 +138,7 @@ exports.request = function(req, res, callback) {
requestH2(client, req, res);
}
} else {
notH2.set(name, 1);
!err && notH2.set(name, 1);
if (pendingItem) {
pendingItem.forEach(function(list) {
list[2](socket);