Permalink
Browse files

Fix http server error reporting

  • Loading branch information...
1 parent 3491bac commit 6a5ac16ca389e451800943e6f8199fc648743090 @ixti ixti committed Apr 15, 2012
Showing with 7 additions and 12 deletions.
  1. +7 −12 lib/init/http_server.js
@@ -35,32 +35,27 @@ function start_server(app, next) {
server = require('http').createServer(app);
err_handler = function (err) {
- if ('EADDRINUSE' === err.code) {
- // port is already in use
- if (3 <= attempt) {
- next("Maximum amount of attempts reached. Can't continue.");
- return;
- }
+ var err_prefix = "Can't bind to <" + host + "> with port <" + port + ">: ";
- attempt += 1;
- nodeca.logger.warn('Address <' + host + ':' + port + '> is in use, retrying... ');
- setTimeout(function () { server.listen(port, host); }, 1000);
+ if ('EADDRINUSE' === err.code) {
+ next(err_prefix + 'Address in use...');
return;
}
if ('EADDRNOTAVAIL' === err.code) {
// system has no such ip address
- next("Address <" + host + ':' + port + '> is not available...');
+ next(err_prefix + 'Address is not available...');
return;
}
if ('ENOENT' === err.code) {
// failed resolve hostname to ip address
- next("Can't resolve address of <" + host + ":" + port + ">...");
+ next(err_prefix + "Failed to resolve IP address...");
return;
}
- next(err);
+ // unexpected / unknown error
+ next(err_prefix + err);
};
server.on('error', err_handler);

0 comments on commit 6a5ac16

Please sign in to comment.