Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios requests not working after update from 0.19.0 to 0.21.1 #3526

Closed
GersonDias opened this issue Jan 5, 2021 · 18 comments
Closed

Axios requests not working after update from 0.19.0 to 0.21.1 #3526

GersonDias opened this issue Jan 5, 2021 · 18 comments
Assignees
Projects
Milestone

Comments

@GersonDias
Copy link

Describe the issue

after updating axios from 0.19 to 0.21.1 I figure out that none of my requests are working in Firefox (it's working on chrome and edge). Not sure how to debug that, I can't even see my request in the network tab... reverting back to 0.19.0 make it work.... there is some breaking change between that updates?

Example Code

return axios({
      url,
      method,
      headers,
      baseURL: apiBaseURL,
      params: method === 'GET' ? data : null,
      data: body,
      onUploadProgress: (progressEvent) => {
        if (progressCallback) {
          progressCallback(progressEvent)
        }
      },
      responseType: isFileDownload ? 'blob' : responseType,
    })
      .then((response) => {
        const resp = {
          is_error: response.status < 200 || response.status > 299,
          content: response.data,
        }

        if (isFileDownload) {
          RestUtils.DownloadFile(response)
        }

        return resp
      })
      .catch((error) => {
        if (error.code === 'ECONNABORTED') {
          return Promise.resolve({ is_error: false, content: [] })
        }
        if (!error.response) {
          return Promise.reject(new Error("request didn't receive a response"))
        } else {
          if (error.response.status === 401) {
            appHistory.push('/logout')
            return Promise.reject(/*new Error('Unauthorized')*/)
          }

          if (error.response.status === 403) {
            return Promise.reject({
              error: 'Action not allowed',
              statusCode: '403',
            })
          }

          return Promise.reject(error)
        }
      })

Expected behavior, if applicable

should work on Firefox with Axios 0.21.1

Environment

  • Axios Version 0.21.1
  • Adapter XHR/HTTP
  • Firefox
  • 84
  • Node.js Version [e.g. 13.0.1]
  • OS: [windows 10]
  • Additional Library Versions React 17.0.1

Additional context/Screenshots

Add any other context about the problem here. If applicable, add screenshots to help explain.

@maxdhn
Copy link

maxdhn commented Jan 5, 2021

Same issue here, when using responseType: 'blob' with Brave browser. I got the following error : Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'blob').

@GersonDias
Copy link
Author

Same issue here, when using responseType: 'blob' with Brave browser. I got the following error : Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'blob').

the request that I'm testing is not using responseType: 'blob', but maybe is related... should I change this to a bug not a question?

@jasonsaayman
Copy link
Member

Hi,

I think your issue has to do with pull request #3289, you will see we are allowing the browser to settle the content type rather than try to dictate it. Also, there was a change to merge config with #2844, so you would need to check if these changes have any bearing on what you are trying to do above? I would try to debug but you have so much going on in one request it can be any amount of things (configs, blob, response type manipulation).

Also, should you be able to would you mind testing with 0.20 and tell us what that does?

@GersonDias
Copy link
Author

I tried with 0.20.0 version and didn't work.

@Crashillo
Copy link

Crashillo commented Jan 7, 2021

Previously, I did my requests like:

const headers = new Headers({
  "Content-type": "application/json"
});

After this update, Firefox throws me invalid header name

I noticed, as a workaround, that setting headers as a plain object works (also it works removing such a common header). So the issue comes up from the Headers interface.

@TravisBumgarner
Copy link

We're also experiencing issues with "Network Error", SSL errors, and more errors.

@nntdias
Copy link

nntdias commented Jan 18, 2021

I'm facing the same issue, PUT and POST requests are not sending the payload.

@BobbiSixkiller
Copy link

Same issue here, after npm prompted me with audit fix during rebuilding my frontend docker container I've updated axios. The next time I've built my container my frontend did not send any requests no matter the browser.

@DRD161
Copy link

DRD161 commented Mar 19, 2021

Same issue here unfortunately. Took several hours to realize axios was the culprit. Rolling back to version 0.19 fixed the issue.

@eddiemonge
Copy link

Also, the way axios handles error responses is a breaking change. Before it would throw if a non-200 was received. Now it does not throw so the response needs to be examined

@nntdias
Copy link

nntdias commented Mar 22, 2021

For me, before this update, I could do something like this.

image

After a few hours debugging this error, I realized that if in the second parameter of the PUT method the value is null, it will not get the data attribute in the options object.

@JSEvgeny
Copy link

JSEvgeny commented Aug 3, 2021

We got the same issue here. Auth1 header don't work any more...

@GersonDias
Copy link
Author

GersonDias commented Sep 2, 2021 via email

@GersonDias
Copy link
Author

I finally got what is going on with this issue

https://codesandbox.io/s/determined-moon-c6cy6?file=/src/App.js

the code

  const headers = new Headers()
  axios({
      ...
      headers: headers
  })

works on version "0.19.x" but not on "0.20.x". Changing to const headers = {} do the trick.

I don't know from where that code comes from (headers = new Headers()) - was a blog post? was a documentation somewhere? was just because intelisense? ) but was that "compatibility break" intentional?

@ergonomicus
Copy link

But that's what is suggested here: #3526 (comment) on January 7th :-)

@GersonDias
Copy link
Author

but others also didn't give attention to @Crashillo comment... it is why I asked if it was intentional or is just my mistake of not properly using the lib... :)

@Crashillo
Copy link

So my comment deserves some emojis to make it relevant...

@jasonsaayman
Copy link
Member

I have released 0.22.0 please check if that fixes your error, if not please open a new issue :)

v0.22.0 automation moved this from To do to Done Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v0.22.0
  
Done
Development

No branches or pull requests