Error connecting to IPFS node

Hi!

I have been using ipfs.infura.io for side project for a bit now.

I am connecting from a node.js app with js-ipfs-http-client

const ipfs = ipfsAPI({ host: 'ipfs.infura.io', port: '5001', protocol: 'https' })

Returning to it yesterday I noticed that attempts to add files fail with the following error:

Caught error: SyntaxError: Unexpected token < in JSON at position 0

Connecting instead to l local IPFS node, it works.

Has there been any changes to the IPFS API? Do i need to include a Project ID or some other authentication?

Grateful for any help!

Hey sorry your experiencing issues, could you provide the full code for the request being generated and a stack trace of the error or a full error response?

Thanks for the reply Mike!

Here is the function:

addText: text => {
    return new Promise((resolve, reject) => {
      ipfs
        .add(Buffer.from(text))
        .then(resolve)
        .catch(error => {
          console.log(error)
          reject(error)
        })
    })
  }

And this is the full error I get in the catch method:

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at streamToValue (/XXX/node_modules/ipfs-http-client/src/utils/stream-to-json-value.js:25:18)
    at concat (/XXX/node_modules/ipfs-http-client/src/utils/stream-to-value.js:12:22)
    at ConcatStream.<anonymous> (/XXX/node_modules/concat-stream/index.js:32:43)
    at ConcatStream.emit (events.js:187:15)
    at finishMaybe (/XXX/node_modules/readable-stream/lib/_stream_writable.js:620:14)
    at afterWrite (/XXX/node_modules/readable-stream/lib/_stream_writable.js:466:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Logging the the data that is supposed to be JSON on line 25 of ipfs-http-client/src/utils/stream-to-json-value.js I get this:

<html>
<head><title>429 Too Many Requests</title></head>
<body bgcolor="white">
<center><h1>429 Too Many Requests</h1></center>
<hr><center>nginx</center>
</body>
</html>

I dont think I am making too many requests! And in fact all requests are failing, even the first. Hmmm…

Thanks for sending this info, where are you sending these requests from? Is it possible you are using an IP that is generating other requests?

I get the same error making the requests from a now.sh deployment and from my local computer, running on different networks.

To update, seems it is a problem of making too many requests (about 150) in parallel (as the error code does in fact indicate!). I am re-writing to make the requests sequentially and this seems to fix it. Thanks a lot for the help troubleshooting this @mike!

1 Like