From c39f4f9738be3d45c0ee3156732b7a2396d79262 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 21 Apr 2014 21:42:59 +0100 Subject: [PATCH] Handle port-in-use error on start-up --- red.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/red.js b/red.js index 01b7f4336..874778714 100644 --- a/red.js +++ b/red.js @@ -163,6 +163,16 @@ function getListenPath() { RED.start().then(function() { if (settings.httpAdminRoot !== false || settings.httpNodeRoot !== false || settings.httpStatic) { + server.on('error', function(err) { + if (err.errno === "EADDRINUSE") { + util.log('[red] Unable to listen on '+getListenPath()); + util.log('[red] Error: port in use'); + } else { + util.log('[red] Uncaught Exception:'); + util.log(err.stack); + } + process.exit(1); + }); server.listen(settings.uiPort,settings.uiHost,function() { if (settings.httpAdminRoot === false) { util.log('[red] Admin UI disabled'); @@ -176,14 +186,9 @@ RED.start().then(function() { process.on('uncaughtException',function(err) { - if (err.errno === "EADDRINUSE") { - util.log('[red] Unable to listen on '+getListenPath()); - util.log('[red] Error: port in use'); - } else { - util.log('[red] Uncaught Exception:'); - util.log(err.stack); - } - process.exit(1); + util.log('[red] Uncaught Exception:'); + util.log(err.stack); + process.exit(1); }); process.on('SIGINT', function () {