From 785b4fe1f8ff71b4c58464f37ab985e57cd16460 Mon Sep 17 00:00:00 2001 From: Stefan Aebischer Date: Fri, 6 Dec 2019 17:20:58 -0500 Subject: [PATCH] Handle server startup errors Resolves: #95 --- built/node_support/node_request_handler.js | 17 +++++++++++------ src/node_support/node_request_handler.ts | 16 +++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/built/node_support/node_request_handler.js b/built/node_support/node_request_handler.js index 38855bd..1d02dd1 100644 --- a/built/node_support/node_request_handler.js +++ b/built/node_support/node_request_handler.js @@ -114,11 +114,16 @@ var NodeBasedHandler = /** @class */ (function (_super) { request.setupCodeVerifier() .then(function () { server = Http.createServer(requestHandler); - server.listen(_this.httpServerPort); - var url = _this.buildRequestUrl(configuration, request); - logger_1.log('Making a request to ', request, url); - opener(url); - emitter.emit(ServerEventsEmitter.ON_START); + server.listen(_this.httpServerPort, function () { + var url = _this.buildRequestUrl(configuration, request); + logger_1.log('Making a request to ', request, url); + opener(url); + emitter.emit(ServerEventsEmitter.ON_START); + }); + server.on('error', function (error) { + logger_1.log('Something bad happened ', error); + emitter.emit(ServerEventsEmitter.ON_UNABLE_TO_START, error); + }); }) .catch(function (error) { logger_1.log('Something bad happened ', error); @@ -140,4 +145,4 @@ var NodeBasedHandler = /** @class */ (function (_super) { return NodeBasedHandler; }(authorization_request_handler_1.AuthorizationRequestHandler)); exports.NodeBasedHandler = NodeBasedHandler; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZV9yZXF1ZXN0X2hhbmRsZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbm9kZV9zdXBwb3J0L25vZGVfcmVxdWVzdF9oYW5kbGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7Ozs7Ozs7O0dBWUc7Ozs7Ozs7Ozs7Ozs7OztBQUVILHFDQUF1QztBQUN2QywyQkFBNkI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gICAgICB9KTtcblxuICAgIHJldHVybiBuZXcgUHJvbWlzZTxudWxsPigocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICBlbWl0dGVyLm9uY2UoU2VydmVyRXZlbnRzRW1pdHRlci5PTl9VTkFCTEVfVE9fU1RBUlQsIChlcnJvcikgPT4ge1xuICAgICAgICByZWplY3QobmV3IEFwcEF1dGhFcnJvcihcbiAgICAgICAgICBgVW5hYmxlIHRvIGNyZWF0ZSBIVFRQIHNlcnZlciBhdCBwb3J0ICR7dGhpcy5odHRwU2VydmVyUG9ydH1gLFxuICAgICAgICAgIHtvcmlnRXJyb3I6IGVycm9yfVxuICAgICAgICApKTtcbiAgICAgIH0pO1xuXG4gICAgICBlbWl0dGVyLm9uY2UoU2VydmVyRXZlbnRzRW1pdHRlci5PTl9TVEFSVCwgKCkgPT4gcmVzb2x2ZShudWxsKSk7XG4gICAgfSk7XG4gIH1cblxuICBwcm90ZWN0ZWQgY29tcGxldGVBdXRob3JpemF0aW9uUmVxdWVzdCgpOiBQcm9taXNlPEF1dGhvcml6YXRpb25SZXF1ZXN0UmVzcG9uc2V8bnVsbD4ge1xuICAgIGlmICghdGhpcy5hdXRob3JpemF0aW9uUHJvbWlzZSkge1xuICAgICAgcmV0dXJuIFByb21pc2UucmVqZWN0KFxuICAgICAgICAgICdObyBwZW5kaW5nIGF1dGhvcml6YXRpb24gcmVxdWVzdC4gQ2FsbCBwZXJmb3JtQXV0aG9yaXphdGlvblJlcXVlc3QoKSA/Jyk7XG4gICAgfVxuXG4gICAgcmV0dXJuIHRoaXMuYXV0aG9yaXphdGlvblByb21pc2U7XG4gIH1cbn1cbiJdfQ== \ No newline at end of file diff --git a/src/node_support/node_request_handler.ts b/src/node_support/node_request_handler.ts index 64908ae..b250a8d 100644 --- a/src/node_support/node_request_handler.ts +++ b/src/node_support/node_request_handler.ts @@ -108,11 +108,17 @@ export class NodeBasedHandler extends AuthorizationRequestHandler { request.setupCodeVerifier() .then(() => { server = Http.createServer(requestHandler); - server.listen(this.httpServerPort); - const url = this.buildRequestUrl(configuration, request); - log('Making a request to ', request, url); - opener(url); - emitter.emit(ServerEventsEmitter.ON_START); + server.listen(this.httpServerPort, () => { + const url = this.buildRequestUrl(configuration, request); + log('Making a request to ', request, url); + opener(url); + emitter.emit(ServerEventsEmitter.ON_START); + }); + + server.on('error', (error: Error) => { + log('Something bad happened ', error); + emitter.emit(ServerEventsEmitter.ON_UNABLE_TO_START, error); + }); }) .catch((error) => { log('Something bad happened ', error);