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

TypeError: Converting circular structure to JSON #6355

Open
zhaoyiming0803 opened this issue Apr 16, 2024 · 2 comments
Open

TypeError: Converting circular structure to JSON #6355

zhaoyiming0803 opened this issue Apr 16, 2024 · 2 comments

Comments

@zhaoyiming0803
Copy link

zhaoyiming0803 commented Apr 16, 2024

Describe the bug

  • axios version: 1.6.8
  • enviroment: node.js
  • node version: v16.14.2
  • npm version: 8.5.0
  • system: mac

Code snippet

const res = await axios.post('https://www.baidu.com', {
      a: 1,
      b: 2
    }, {
      headers: {
        'Content-Type': 'application/json'
      }
    })


### Expected behavior

solve circular error
@RonDaha
Copy link

RonDaha commented Apr 30, 2024

I also experience the same issue, although in my case this issue occuer only when the data object have a property with the key query and the value is a string

For example

This produce the error:

axios.request({
        method: "POST",
        URL: "some-url",
        headers: {  'Content-Type': 'application/json' },
        data: { query: "any value" },
    })

This does not produce the error:

axios.request({
        method: "POST",
        url: "some-url",
        headers: {  'Content-Type': 'application/json' },
        data: { notQuery: "any value" },
    })

The error:
AppError [TypeError]: Converting circular structure to JSON --> starting at object with constructor 'ClientRequest' | property 'socket' -> object with constructor 'TLSSocket' --- property '_httpMessage' closes the circle

  • axios version: 1.6.8
  • enviroment: node.js
  • node version: v18.17.1
  • npm version: 9.6.7
  • system: macOS 14.4 (23E214)

@zhaoyiming0803
Copy link
Author

I also experience the same issue, although in my case this issue occuer only when the data object have a property with the key query and the value is a string

For example

This produce the error:

axios.request({
        method: "POST",
        URL: "some-url",
        headers: {  'Content-Type': 'application/json' },
        data: { query: "any value" },
    })

This does not produce the error:

axios.request({
        method: "POST",
        url: "some-url",
        headers: {  'Content-Type': 'application/json' },
        data: { notQuery: "any value" },
    })

The error: AppError [TypeError]: Converting circular structure to JSON --> starting at object with constructor 'ClientRequest' | property 'socket' -> object with constructor 'TLSSocket' --- property '_httpMessage' closes the circle

  • axios version: 1.6.8
  • enviroment: node.js
  • node version: v18.17.1
  • npm version: 9.6.7
  • system: macOS 14.4 (23E214)

I use Axios in Node.js enviroment (Koa.js framework):

const res = await Axios.request()

// error
ctx.body = {
   data: res
}

// no error
ctx.body = {
   data: res.data
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants