This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ProgBlog/app/base/Server.js
2016-02-19 12:58:16 -05:00

42 lines
829 B
JavaScript

'use strict';
/**
* Base Class for wrapping HTTP/HTTPS servers
*/
class Server {
constructor() {}
/**
* Event listener for HTTP(s) server "error" event.
*
* @param {error} error - the error object
* @return {null} - Does not return a value
* @throws {error}
*/
onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
let port = this.server.address().port;
let bind = typeof port === 'string'
? `Pipe ${port}`
: `Port ${port}`;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
logger.error(`${bind} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
logger.error(`${bind} is already in use`);
process.exit(1);
break;
default:
throw error;
}
}
}
module.exports = Server;