This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
ipfs.dht.findProvs() can't catch error with fake hash #928
Closed
Description
We want to implement a 'exist' function to judge if provided hash is exist in the private ipfs network. We use ipfs.dht.findProvs() to achieve this logic like this:
ipfs.dht.findProvs(hash)
.then(resp => {...})
.catch(e => {...})
but we found that if the hash is valid but not exist, it will throw an error that can't catch in promise:
Uncaught TypeError: Cannot read property 'Type' of undefined
after see the source code, we found this:
const handleResult = (res, callback) => {
// 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)`
return callback(errcode(new Error(errMsg), 'ERR_KEY_TYPE_4_NOT_FOUND'))
}
.....
It means that the res is undefined when hash is not exist?
or would you please give us a better way to achieve the 'exist' function