axios: Axios breaking changes in simple requests beginning with 0.21.2 and up coming from v0.21.1

Describe the issue

Using Axios to refresh Twitch Token suddenly breaks when updating from v0.21.1 to 0.21.2 and newer.

Example Code

It works jsut fine in v0.21.1 but breaks in higher versions. An example usage is down below.

The main issue here is that I get the emssage that the “client_id” is missing by twitch API, although as you can see it is included in the options object. Something must have changed in v0.21.2 and higher for this to happen somehow suddenly

const Axios = include('axios');

options= {
  method: 'post',
  baseURL: 'https://id.twitch.tv/oauth2/',
  url: 'token',
  params: {
    grant_type: 'refresh_token',
    refresh_token: '---------',
    client_id: '---------',
    client_secret: '---------'
  },
  headers: {},
  data: {}
}

Axios(options)

Expected behavior, if applicable

It should work and send everything provided including the client_id of course as in the example above

Environment

  • Axios Version 0.21.2
  • Adapter HTTP
  • Node.js Version 8.x
  • OS: Win 10

Additional context/Screenshots

Pls help me updating to v0.22.0 by somehow pointing me in the right direction to solve this, thanks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 17 (2 by maintainers)

Most upvoted comments

Hi, thank you for the input all. But I feel I should have been clearer in my word choice.

I did state

v0.21.2 and higher and It works jsut fine in v0.21.1 but breaks in higher versions.

So I really meant in higher versions and not jsut in v0.21.2.

I tested first udpating to v0.22.0 and saw it broke, then I backtracked every version trying v0.21.4, v0.21.3 and v0.21.2 and therefore I could conclude that there was some major change done in v0.21.2 that my code breaks. In v0.21.1 the code works perfectly fine like it should, jsut to make it clear.

An example was already given how I do it and yeah this is all I can say for now. I wanna request to open this issue again @jasonsaayman please and hope that it can be looked into again.

I am gonna take a look at comparing the changes amde from v0.21.1 -> v0.21.2 over the weekend when I have more time but I hope I can get some extra eyes to help with that and fix that issue with Axios.

Thank you!

The most possible buggy commit may be #3688, which changes the default transformRequest. And looks like ‘Content-Type’: ‘application/json’ is set by @JaielSoft in https://github.com/axios/axios/issues/4129#issuecomment-933486751, which matches the problem of @cruizba in https://github.com/axios/axios/issues/4129#issuecomment-936146851.

-    if (utils.isObject(data)) {
+    if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
       setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
       return JSON.stringify(data);
     }

And I have a very simple template to debug the config related issues. Please try and compare the adapter printed config between different axios versions.

var adapter = function(config) {
  console.log(config)
  return Promise.resolve({data: 12})
}

// set the log adapter
axios({ adapter, ... })