contentful / contentful.js

JavaScript library for Contentful's Delivery API (node & browser)
https://contentful.github.io/contentful.js
MIT License
1.2k stars 200 forks source link

Retried requests duplicate query parameters resulting in 400 response #2246

Closed geigerzaehler closed 5 months ago

geigerzaehler commented 5 months ago

When a request is retried query parameters are duplicated which results in a 400 response.

This is a bit tricky to reproduce, but possible with Chrome Dev Tools’ network request blocking feature. I have a simple script that I load in the browser:

await client.getEntries({ contentType: "foo" })

In the dev tools I add “contentful“ to the list of blocked requests. image

Then I reload the page. In the network tab of the dev tools I can see that requests to contentful are blocked. I quickly uncheck contentful in the request blocking tab to let it go through. But the server responds with a 400 and the message “The query you sent included duplicate URI query parameters...”.

image

From the network tab I can see that the request URL looks like this:

https://cdn.contentful.com/spaces/m2xydvefjw31/environments/master/entries?content_type=foo&content_type=foo&content_type=foo

It looks like every retry appends the query string again.

This issue started to occur in 10.11.1 and wasn’t present in 10.11.0.

Techn1x commented 5 months ago

We're experiencing the same issue from the same version and have put through a support request to contentful

t-col commented 5 months ago

Hi @geigerzaehler thanks for reporting. A stack trace of the The query you sent included duplicate URI query parameters error would be helpful in diagnosing where this problem is occurring. I have not been able to reproduce yet with the same setup you're describing.

geigerzaehler commented 5 months ago

Thanks for taking a look @t-col. Here’s the stack trace:

BadRequest
    at Ur (http://localhost:3000/node_modules/.vite/deps/contentful.js?v=9eaebbc3:6774:22)
    at a2 (http://localhost:3000/node_modules/.vite/deps/contentful.js?v=9eaebbc3:7217:17)
    at async u2 (http://localhost:3000/node_modules/.vite/deps/contentful.js?v=9eaebbc3:7224:27)
   [REDACTED]

It looks like the package does not provide any sourcemaps so this doesn’t look helpful unfortunately.

Can I make the steps to reproduce the issue clearer in any way? Which part can’t you reproduce?

Techn1x commented 5 months ago

If it helps, I was able to reproduce this with some simple steps:

It's a supplemental step to then go back online in Dev tools and see that the next request when internet is available will return with 400 error from server because it has incorrect query params. The issue isn't so much to do with the error itself, but rather whatever is retrying the request is doing so incorrectly.

t-col commented 5 months ago

@geigerzaehler in the interest of thoroughness - are you passing in any custom configuration to the underlying axios instance from within the wrapping vite application? i.e.

const client = createClient({
  space: '<your_space>',
  accessToken: '<your_token>',
  // ... other configuration
})
geigerzaehler commented 5 months ago

are you passing in any custom configuration to the underlying axios instance from within the wrapping vite application?

No, I’m only passing space and access token to createClient.

Techn1x commented 5 months ago

repro video

https://github.com/contentful/contentful.js/assets/1049837/e1ac7ac8-6b6a-475d-9fcf-0ea3b1e41d16

here's the 400 response if you need it. It's BadRequest due to the duplicated query params. Screenshot 2024-06-12 at 7 17 05 pm

t-col commented 5 months ago

fixed in v10.11.11