diff --git a/src/core/components/bitswap.js b/src/core/components/bitswap.js index 4b3b7b7e99..373de852b8 100644 --- a/src/core/components/bitswap.js +++ b/src/core/components/bitswap.js @@ -10,7 +10,7 @@ module.exports = function bitswap (self) { return { wantlist: () => { if (!self.isOnline()) { - throw OFFLINE_ERROR + throw new Error(OFFLINE_ERROR) } const list = self._bitswap.getWantlist() @@ -18,7 +18,7 @@ module.exports = function bitswap (self) { }, stat: () => { if (!self.isOnline()) { - throw OFFLINE_ERROR + throw new Error(OFFLINE_ERROR) } const stats = self._bitswap.stat() @@ -29,7 +29,7 @@ module.exports = function bitswap (self) { }, unwant: (key) => { if (!self.isOnline()) { - throw OFFLINE_ERROR + throw new Error(OFFLINE_ERROR) } // TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged diff --git a/src/core/components/pubsub.js b/src/core/components/pubsub.js index b0a1eb283d..5feadfaf68 100644 --- a/src/core/components/pubsub.js +++ b/src/core/components/pubsub.js @@ -9,7 +9,7 @@ module.exports = function pubsub (self) { return { subscribe: (topic, options, handler, callback) => { if (!self.isOnline()) { - throw OFFLINE_ERROR + throw new Error(OFFLINE_ERROR) } if (typeof options === 'function') { @@ -44,7 +44,7 @@ module.exports = function pubsub (self) { publish: promisify((topic, data, callback) => { if (!self.isOnline()) { - return setImmediate(() => callback(OFFLINE_ERROR)) + return setImmediate(() => callback(new Error(OFFLINE_ERROR))) } if (!Buffer.isBuffer(data)) { @@ -57,7 +57,7 @@ module.exports = function pubsub (self) { ls: promisify((callback) => { if (!self.isOnline()) { - return setImmediate(() => callback(OFFLINE_ERROR)) + return setImmediate(() => callback(new Error(OFFLINE_ERROR))) } const subscriptions = Array.from( @@ -69,7 +69,7 @@ module.exports = function pubsub (self) { peers: promisify((topic, callback) => { if (!self.isOnline()) { - return setImmediate(() => callback(OFFLINE_ERROR)) + return setImmediate(() => callback(new Error(OFFLINE_ERROR))) } const peers = Array.from(self._pubsub.peers.values()) diff --git a/src/core/components/swarm.js b/src/core/components/swarm.js index f243618a6e..822279f820 100644 --- a/src/core/components/swarm.js +++ b/src/core/components/swarm.js @@ -15,7 +15,7 @@ module.exports = function swarm (self) { } if (!self.isOnline()) { - return callback(OFFLINE_ERROR) + return callback(new Error(OFFLINE_ERROR)) } const verbose = opts.v || opts.verbose @@ -46,7 +46,7 @@ module.exports = function swarm (self) { // all the addrs we know addrs: promisify((callback) => { if (!self.isOnline()) { - return callback(OFFLINE_ERROR) + return callback(new Error(OFFLINE_ERROR)) } const peers = values(self._peerInfoBook.getAll()) @@ -56,7 +56,7 @@ module.exports = function swarm (self) { localAddrs: promisify((callback) => { if (!self.isOnline()) { - return callback(OFFLINE_ERROR) + return callback(new Error(OFFLINE_ERROR)) } callback(null, self._libp2pNode.peerInfo.multiaddrs.toArray()) @@ -64,7 +64,7 @@ module.exports = function swarm (self) { connect: promisify((maddr, callback) => { if (!self.isOnline()) { - return callback(OFFLINE_ERROR) + return callback(new Error(OFFLINE_ERROR)) } if (typeof maddr === 'string') { @@ -76,7 +76,7 @@ module.exports = function swarm (self) { disconnect: promisify((maddr, callback) => { if (!self.isOnline()) { - return callback(OFFLINE_ERROR) + return callback(new Error(OFFLINE_ERROR)) } if (typeof maddr === 'string') { diff --git a/src/core/utils.js b/src/core/utils.js index 9203aacb4e..a492250383 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -1,3 +1,3 @@ 'use strict' -exports.OFFLINE_ERROR = new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.') +exports.OFFLINE_ERROR = 'This command must be run in online mode. Try running \'ipfs daemon\' first.'