From 2a7ac473254f554287c4048d90d86877901c5afc Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 2 Mar 2018 14:35:00 +0000 Subject: [PATCH] Emit error (instead of failing). Previously, if no player app loaded, an asynchronous exception was raised. There was no way to catch this exception, and therefore no possibility to recover. Instead, emit an error. --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4bbe265..239871b 100644 --- a/index.js +++ b/index.js @@ -160,13 +160,18 @@ player.prototype._connect = function(ctx) { // find running app player.prototype._find = function(ctx) { + var that = this; this._setStatus(ctx, 'finding'); return new Promise(function(resolve, reject) { ctx.client.getSessions(function(err, apps) { if (err) return reject(err); - if (!apps.length) return reject(new Error('app not found')); - ctx.session = apps[0]; - resolve(ctx); + if (apps.length) { + ctx.session = apps[0]; + resolve(ctx); + } else { + that.emit("error", "app not found"); + reject("app not found"); + } }); }); };