From abafecd1d44e768041e85ee6cb34d306167df809 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 16 Oct 2017 10:04:14 -0700 Subject: [PATCH] Tweak: Mac autoupdate module passes Error, unwrap in hanlder for Win/Linux too --- app/src/browser/autoupdate-impl-base.es6 | 54 ++++++++++++------------ app/src/browser/autoupdate-manager.es6 | 4 +- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/app/src/browser/autoupdate-impl-base.es6 b/app/src/browser/autoupdate-impl-base.es6 index 01e49d744..6672d9c07 100644 --- a/app/src/browser/autoupdate-impl-base.es6 +++ b/app/src/browser/autoupdate-impl-base.es6 @@ -19,8 +19,8 @@ export default class AutoupdateImplBase extends EventEmitter { this.lastRetrievedUpdateURL = null; } - emitError = err => { - this.emit('error', err.message); + emitError = error => { + this.emit('error', error); }; manuallyQueryUpdateServer(successCallback) { @@ -29,32 +29,34 @@ export default class AutoupdateImplBase extends EventEmitter { // Hit the feed URL ourselves and see if an update is available. // On linux we can't autoupdate, but we can still show the "update available" bar. - https.get({ host: feedHost, path: feedPath }, res => { - console.log(`Manual update check (${feedHost}${feedPath}) returned ${res.statusCode}`); + https + .get({ host: feedHost, path: feedPath }, res => { + console.log(`Manual update check (${feedHost}${feedPath}) returned ${res.statusCode}`); - if (res.statusCode === 204) { - successCallback(false); - return; - } - - let data = ''; - res.on('error', this.emitError); - res.on('data', chunk => { - data += chunk; - }); - res.on('end', () => { - try { - const json = JSON.parse(data); - if (!json.url) { - this.emitError(new Error(`Autoupdater response did not include URL: ${data}`)); - return; - } - successCallback(json); - } catch (err) { - this.emitError(err); + if (res.statusCode === 204) { + successCallback(false); + return; } - }); - }).on('error', this.emitError); + + let data = ''; + res.on('error', this.emitError); + res.on('data', chunk => { + data += chunk; + }); + res.on('end', () => { + try { + const json = JSON.parse(data); + if (!json.url) { + this.emitError(new Error(`Autoupdater response did not include URL: ${data}`)); + return; + } + successCallback(json); + } catch (err) { + this.emitError(err); + } + }); + }) + .on('error', this.emitError); } /* Public: Check for updates and emit events if an update is available. */ diff --git a/app/src/browser/autoupdate-manager.es6 b/app/src/browser/autoupdate-manager.es6 index fa75e9e76..d7cd54639 100644 --- a/app/src/browser/autoupdate-manager.es6 +++ b/app/src/browser/autoupdate-manager.es6 @@ -62,9 +62,9 @@ export default class AutoUpdateManager extends EventEmitter { autoUpdater = require('electron').autoUpdater; } - autoUpdater.on('error', (message) => { + autoUpdater.on('error', error => { if (this.specMode) return; - console.error(`Error Downloading Update: ${message}`); + console.error(`Error Downloading Update: ${error.message}`); this.setState(ErrorState); });