Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: handle empty array return value in dht.findProvs (#1003)
Browse files Browse the repository at this point in the history
Correcting the array check to happen before the individual element checks. fixes #928
  • Loading branch information
KrishnaPG authored and Alan Shaw committed May 17, 2019
1 parent c39206d commit 15ab7c5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/dht/findprovs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down

0 comments on commit 15ab7c5

Please sign in to comment.