From 3bf5093f1b3ef3f792944cbbae5b794abb6461a0 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 1 May 2018 10:20:27 -0400 Subject: [PATCH] more linting and add condition in case of no hash --- lib/modules/swarm/embarkjs.js | 7 +++---- lib/modules/swarm/upload.js | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/modules/swarm/embarkjs.js b/lib/modules/swarm/embarkjs.js index f46b8681d..9a415258a 100644 --- a/lib/modules/swarm/embarkjs.js +++ b/lib/modules/swarm/embarkjs.js @@ -11,7 +11,7 @@ __embarkSwarm.setProvider = function (options) { this.connectError = new Error(`Cannot connect to Swarm node on ${this.connectUrl}`); this._getUrl = options.getUrl || `${this.connectUrl}/bzzr:/`; - var promise = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { try { if (!this.bzz.currentProvider) { this.bzz.setProvider(`${options.protocol}://${options.host}:${options.port}`); @@ -22,7 +22,6 @@ __embarkSwarm.setProvider = function (options) { reject(this.connectError); } }); - return promise; }; __embarkSwarm.isAvailable = function () { @@ -72,9 +71,9 @@ __embarkSwarm.uploadFile = function (inputSelector) { } return new Promise((resolve, reject) => { - var reader = new FileReader(); + const reader = new FileReader(); reader.onloadend = (event) => { - var fileContent = new Uint8Array(event.target.result); + const fileContent = new Uint8Array(event.target.result); this.isAvailable().then((isAvailable) => { if (!isAvailable) { return reject(this.connectError); diff --git a/lib/modules/swarm/upload.js b/lib/modules/swarm/upload.js index 0c00aad8a..fbe64924a 100644 --- a/lib/modules/swarm/upload.js +++ b/lib/modules/swarm/upload.js @@ -28,6 +28,9 @@ class Swarm { .catch(callback); }, function printUrls(dir_hash, callback) { + if (!dir_hash) { + return callback('No directory hash was returned'); + } console.log((`=== DApp available at ${self.storageConfig.getUrl}${dir_hash}/`).green); callback(); @@ -36,9 +39,9 @@ class Swarm { if (err) { console.log("error uploading to swarm".red); console.log(err); - reject(err); + return reject(err); } - else resolve('successfully uploaded to swarm'); + resolve('successfully uploaded to swarm'); }); }); }