From a93818469347b3fbdbb1d3d7bef59fc9b1268c74 Mon Sep 17 00:00:00 2001 From: Gopalakrishna Palem Date: Thu, 16 May 2019 19:55:41 +0530 Subject: [PATCH] Handle Empty Array return values Correcting the array check to happen before the individual element checks. Issue: https://github.com/ipfs/js-ipfs-http-client/issues/928 --- src/dht/findprovs.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dht/findprovs.js b/src/dht/findprovs.js index dd2d82f58..acfd1329f 100644 --- a/src/dht/findprovs.js +++ b/src/dht/findprovs.js @@ -23,17 +23,17 @@ module.exports = (send) => { } const handleResult = (res, callback) => { + // Inconsistent return values in the browser vs node + if (Array.isArray(res)) { + res = res[0] + } + // callback with an empty array if no providers are found if (!res) { const responses = [] return callback(null, responses) } - // Inconsistent return values in the browser vs node - if (Array.isArray(res)) { - res = res[0] - } - // Type 4 keys if (res.Type !== 4) { const errMsg = `key was not found (type 4)`