Skip to content

Commit 15ab7c5

Browse files
KrishnaPGAlan Shaw
authored and
Alan Shaw
committed
fix: handle empty array return value in dht.findProvs (ipfs#1003)
Correcting the array check to happen before the individual element checks. fixes ipfs-inactive/js-ipfs-http-client#928
1 parent c39206d commit 15ab7c5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/dht/findprovs.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ module.exports = (send) => {
2323
}
2424

2525
const handleResult = (res, callback) => {
26+
// Inconsistent return values in the browser vs node
27+
if (Array.isArray(res)) {
28+
res = res[0]
29+
}
30+
2631
// callback with an empty array if no providers are found
2732
if (!res) {
2833
const responses = []
2934
return callback(null, responses)
3035
}
3136

32-
// Inconsistent return values in the browser vs node
33-
if (Array.isArray(res)) {
34-
res = res[0]
35-
}
36-
3737
// Type 4 keys
3838
if (res.Type !== 4) {
3939
const errMsg = `key was not found (type 4)`

0 commit comments

Comments
 (0)