formatting server error

This commit is contained in:
Ricardo Gobbo de Souza 2018-11-27 18:52:15 -02:00 committed by GitHub
parent 21eda65cb4
commit 1113b5d117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,10 +55,7 @@ export default class Listener {
this._server = protocol.createServer.apply(protocol, protocolOpts.concat(this.app))
// Listen server error
/* istanbul ignore next */
this._server.on('error', (e) => {
consola.error(e)
})
this._server.on('error', this.errorHandler)
// Prepare listenArgs
const listenArgs = this.socket ? { path: this.socket } : { host: this.host, port: this.port }
@ -78,4 +75,14 @@ export default class Listener {
// Set this.listening to true
this.listening = true
}
errorHandler(e) {
const errors = {
EACCES: 'Permission denied. Does your user have permission?',
EADDRINUSE: `Address \`${this.host}:${this.port}\` is already in use. Do you run another service on the same port?`,
EDQUOT: 'Disk quota exceeded. Do you have space in disk?'
};
consola.error(errors[e.code] || e);
}
}