BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.17k stars 754 forks source link

Handle localtunnel throwing error from ECONNREFUSED #823

Open michaelgilley opened 9 years ago

michaelgilley commented 9 years ago

Ref #755

This is actually an issue with browser-sync not handling the emitted error from localtunnel. Localtunnel will automatically attempt to reconnect the tunnel after this but if the error event is unhandled EventEmitter will throw the error, thereby crashing apps (e.g., say when using within a Gulp task).

I think this would be covered but simply binding to the error event within /lib/tunnel.js and maybe logging out the error? I have saved this from crashing by doing the following:

var inst = browserSync.init({
    proxy: 'localhost:4000'
  , tunnel: process.env.TUNNEL_SUBDOMAIN
  , open: !~process.argv.indexOf('--bg')
  , notify: false
  })

  inst.emitter.on('service:running', function() {
    inst.tunnel.tunnel_cluster.on('error', function(err) {
      if (!~err.toString().indexOf('firewall')) throw err
      log('Tunnel Reconnecting...')
    })
  })
shakyShane commented 8 years ago

Sounds like you're ready for a PR here - https://github.com/BrowserSync/browser-sync/blob/master/lib/tunnel.js