mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
add error handlers to requests and sockets
Trying to flush out cause of sporadic socket failures and identify which socket is not being handled.
This commit is contained in:
17
server.js
17
server.js
@@ -301,6 +301,15 @@ module.exports = function(opt) {
|
||||
const server = http.createServer();
|
||||
|
||||
server.on('request', function(req, res) {
|
||||
|
||||
req.on('error', (err) => {
|
||||
console.error('request', err);
|
||||
});
|
||||
|
||||
res.on('error', (err) => {
|
||||
console.error('response', err);
|
||||
});
|
||||
|
||||
debug('request %s', req.url);
|
||||
if (maybe_bounce(req, res, null, null)) {
|
||||
return;
|
||||
@@ -310,6 +319,14 @@ module.exports = function(opt) {
|
||||
});
|
||||
|
||||
server.on('upgrade', function(req, socket, head) {
|
||||
req.on('error', (err) => {
|
||||
console.error('ws req', err);
|
||||
});
|
||||
|
||||
socket.on('error', (err) => {
|
||||
console.error('ws socket', err);
|
||||
});
|
||||
|
||||
if (maybe_bounce(req, null, socket, head)) {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -28,16 +28,8 @@ test('landing page', function(done) {
|
||||
|
||||
var req = http.request(opt, function(res) {
|
||||
res.setEncoding('utf8');
|
||||
var body = '';
|
||||
|
||||
res.on('data', function(chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
res.on('end', function() {
|
||||
assert(body.indexOf('Redirecting to https://localtunnel.github.io/www/') > 0);
|
||||
done();
|
||||
});
|
||||
assert.equal(res.headers.location, 'https://localtunnel.github.io/www/')
|
||||
done();
|
||||
});
|
||||
|
||||
req.end();
|
||||
|
||||
Reference in New Issue
Block a user