diff --git a/lib/Client.js b/lib/Client.js index dd78f78..10ee3e2 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -55,7 +55,7 @@ class Client extends EventEmitter { this.emit('close'); } - handleRequest(req, res) { + handleRequest(req, res, retry = true) { this.debug('> %s', req.url); const opt = { path: req.url, @@ -74,6 +74,7 @@ class Client extends EventEmitter { pump(clientRes, res, (err) => { if (err) { this.debug('> PIPE ERROR, %s', err); + this.debug(err); } }); }); @@ -83,14 +84,21 @@ class Client extends EventEmitter { // if we have already sent headers? clientReq.once('error', (err) => { // TODO(roman): if headers not sent - respond with gateway unavailable - this.debug('ERROR < %s', req.url); + this.debug(' < ERROR %s', req.url); this.debug(err); + this.debug(JSON.stringify( err )); + + if (retry) { + this.debug('< RETRY'); + this.handleRequest( req, res, false); + } }); // using pump is deliberate - see the pump docs for why pump(req, clientReq, (err) => { if (err) { this.debug('< PIPE ERROR, %s', err); + this.debug(err); } }); } diff --git a/server.js b/server.js index 435f1d9..5792445 100644 --- a/server.js +++ b/server.js @@ -143,6 +143,7 @@ export default function(opt) { const clientId = GetClientIdFromHostname(hostname); if (!clientId) { appCallback(req, res); + debug('ClientID for host %s was not found :(', hostname); return; }