INFURA / infura

Official Public Repository for INFURA
https://infura.io
380 stars 62 forks source link

`Error: Invalid JSON RPC response: ""` on `getPastEvents` #135

Open LiorRabin opened 6 years ago

LiorRabin commented 6 years ago

This is a snippet of my code:

MyContract.getPastEvents('SomeEvent', {fromBlock: fromBlock, toBlock: 'latest'})
  .then(pastEvents => {
    console.log(`SomeEvent events ${JSON.stringify(pastEvents)}`)
    if (!pastEvents || pastEvents.length === 0) {
      return
    }
    pastEvents.forEach(onSomeEventEvent)
  })
  .catch(err => {
    console.error(`SomeEvent events error: ${JSON.stringify(err)}`)
  })

Sometimes I see in log:

Error: Invalid JSON RPC response: "<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>502 Bad Gateway</h1></center>\r\n</body>\r\n</html>\r\n"

Sometimes I see this:

Error: Invalid JSON RPC response: ""

And sometimes everything is ok.

This happens on https://mainnet.infura.io/<API_KEY> and on https://ropsten.infura.io/<API_KEY>

What am I doing/understanding wrong here?

Thanks

barrard commented 6 years ago

Im getting this same error using Rinkeby network. It used to be a rare occurrence, but it's happening more frequently all of a sudden.

melnikaite commented 6 years ago

Everything is fine for https://kovan.infura.io/v3/<api key>, but I'm getting Error: Invalid JSON RPC response: "" too often for https://ropsten.infura.io/v3/<api key> and https://mainnet.infura.io/v3/<api key>. I tried to do requests in sequence with small delay instead of parallel, but it didn't help. Also I noticed that requests with fromBlock: 2000001 fails more often than with higher block numbers.