diff --git a/src/components/P2P/index.ts b/src/components/P2P/index.ts index b56906f8b..68062ac6b 100644 --- a/src/components/P2P/index.ts +++ b/src/components/P2P/index.ts @@ -591,8 +591,8 @@ export class OceanP2P extends EventEmitter { } async findPeerInDht(peerName: string, timeout?: number) { - const peer = peerIdFromString(peerName) try { + const peer = peerIdFromString(peerName) const data = await this._libp2p.peerRouting.findPeer(peer, { signal: isNaN(timeout) || timeout === 0 diff --git a/src/components/httpRoutes/getOceanPeers.ts b/src/components/httpRoutes/getOceanPeers.ts index 0cf4e25d0..5ed5caa05 100644 --- a/src/components/httpRoutes/getOceanPeers.ts +++ b/src/components/httpRoutes/getOceanPeers.ts @@ -31,7 +31,8 @@ getOceanPeersRoute.get( const peers = await req.oceanNode .getP2PNode() .findPeerInDht(String(req.query.peerId), parseInt(String(req.query.timeout))) - res.json(peers) + if (peers) res.json(peers) + else res.sendStatus(404).send('Cannot find peer') } else { sendMissingP2PResponse(res) }