Michael Cranston

Gulp - Fix to socket hang up using httpProxy

If you use the Yeoman Gulp generator, you might be getting an incredibly frustrating socket hang up anytime an HTTP request fails or is interrupted.

Error: socket hang up
    at createHangUpError (http.js:1472:15)
    at CleartextStream.socketCloseListener (http.js:1522:23)
    at CleartextStream.emit (events.js:95:17)
    at tls.js:693:10
    at process._tickCallback (node.js:419:13)

Adding simple error handling to your httpProxy will disallow the hangup and keep your sanity in check:

var proxy = httpProxy.createProxyServer({
  target: proxyTarget
}).on('error', function(e) {
  console.log(JSON.stringify(e, null, ' '))
});
comments powered by Disqus