OpenSea Clone Tutorial - 400 errors

I was doing the Opensea Clone course, and quite often, some of the API calls to Moralis will fail.

Sometimes it’s the one that gets the balance, sometimes it’s the one that gets your NFTs… So different aspects of the UI end up not having the data they need, at different times.

Could be a load issue.

Does the paid version of Moralis work better?

please post exact requests you are having issues with

I saw this just now:

Failed to load resource: the server responded with a status of 400 ()

And if I refresh the page a few times, it’ll usually work after a bit…

I was considering just building a retry into the site so that I’d eventually get the data. I just don’t like the idea of implementing such workarounds at the beginning of a project.

I’ve also seen this previously:

Failed to load resource: the server responded with a status of 400 ()

Although, since I recreated the server recently to get it to the latest version, ryzdy5wharle may not have logs of all of the errors.

Overall, the errors are seemingly random. Sometimes all requests will succeed, sometimes one or more will fail.

Are you making lots of requests? In case of making a lot of requests there will be a rate limit

That should be 429 instead of 400, and no.

I’m just going through the course, so it’s the normal number of API calls when a web page is loaded in the browser.

Like I just refreshed and out of

The first one /getNFTs failed.

I do feel that that one fails more often than the other ones, but that may be because it’s more obvious when it happens.

it looks like the I see errors of this type: required param address not provided. that could mean that user is not authenticated and address was not provided

Yes, one would think so. 400 does mean Bad Request.

But it’s the same code that works across page loads, and it’s not really my code.

It’s the account.getNFTs function from useMoralisWeb3ApiCall()

can you provide de address in that call explicitly?

There’s no obvious system for doing that.

useMoralisWeb3Api() is part of the ‘react-moralis’ library.

I’d need to go in and modify that to hard code an address I’m sending… And it may have some dependence on the MetaMask integration.

you can use Network tab in chrome to see full request failing

1 Like

the address in only a parameter to that function, that it is automatically added when user is authenticated when it was not provided explicitly

@cryptokid It does appear to be the case that the request itself is malformed when I look at it in Network.

When it succeeds, it is sending { chain, address }, and when it’s failing, it’s sending only { chain }

do you get same error with you login with metamask into the site?

I’m only using MetaMask for login, and I’ve never logged out.

that address parameter is not really taken from metamask, it is from current authenticated user, maybe when you refresh the page the user object is not yet initialised when it tries to make that request?

That does sound likely.

It may be that the /getNFT call can end up happening before the account object is fully initialized.

So the timing of various events could be the problem.

I’m thinking that it’s possible that because there are multiple page mutations, and /getNFTs ends up called multiple times… That in some cases, the failed request might be overwriting the successful result.

Although that’s more an idea that I plan to test.