ipfs-webui
ipfs-webui copied to clipboard
ipfs daemon --offline returns 400 for /api/v0/stats/bw
If your run
ipfs daemon --offline
then the API responds to requests for /api/v0/stats/bw with a 400 status code and the body:
{"Message":"this command must be run in online mode. Try running 'ipfs daemon' first","Code":1,"Type":"error"}
as we're using the bandwidth stats to determine if the connection is working, the Web UI asserts that the connection to IPFS has failed.
We need to handle the situation where the stats/bw response is a 400 for offline mode. The connection is fine in that case, and the status page should inform the user that the node is in offline mode, in place of the bandwidth graph and the distribution of peers graph. They'll never show anything while we're offline anyway.
The peers page will show 0 peers, so it'd be worth adding a message on that page that explains why.
The connection indicator should be updated to denote that we are connected to IPFS but in offline mode.
@olizilla is the current behavior satisfactory to close this issue or is something missing?
@rafaelramalho19 I was revisiting this while testing https://github.com/ipfs-shipyard/ipfs-companion/pull/936 and this is still a problem.
When I run daemon in offline mode (ipfs daemon --offline) Web UI online check fails, stats.bw returns HTTP 400 when daemon runs in --offline mode, which in turn triggers "api is down" error page:
So we need fix described in https://github.com/ipfs-shipyard/ipfs-webui/issues/853#issuecomment-427660070 and a smarter detection of the --offline mode. It can be done by:
let peers
try {
peers = await ipfs.swarm.peers({ timeout: 2500 })
} catch (error) {
if (error.message.includes('action must be run in online mode')) {
// node is running in offline mode (ipfs daemon --offline)
// https://github.com/ipfs-shipyard/ipfs-companion/issues/790
return [] // ipfs daemon --offline
}
// actual error handling...
}
- switch API check from
stats.bwtoswarm.peers - return empty peer list when in offline mode (instead of error)
- make it not fail when there are no peers
Fetching the bandwidth usage seems like it would of course error when offline. So some other method to check if the daemon is running should be used. Unfortunately, none of the commands in the documentation seem like simple pulse checks. Maybe id or commands?
