Node.js SDK response.body vs response.result

Hello. I’ve been using the node.js SDK. I’m able to output data from my server in the terminal. I’m also able to get data to the client(DOM). I’m able to do this by using res.send(response.body), which is a string in the terminal, but once it gets to the client the data is an object (as expected, & desired). If I do res.send(response) in the server I get data in the server terminal but an error at the client. I’m wanting to know why that is because the docs mentions “response.result” & not “response.body”. Thank you!

app.get('/test', async (req, res) => {
  try {
    const response = await client.customersApi.listCustomers()
    console.log(response.result)
    res.send(response.body) // displays in server, & displays in client
    // res.send(response.result) // displays in server, throws error in client
  } catch(error) {
    console.log(error)
  }
})

What’s the error your getting on the client? :slight_smile:

Apologies, I misspoke. I had recently switched some things around. I’m getting an error on the server when I attempt to call res.send(response.result) to the client. This is the error I’m getting.

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at stringify (/Users/user_name/Projects/demo-node-request/node_modules/express/lib/response.js:1150:12)
    at ServerResponse.json (/Users/user_name/Projects/demo-node-request/node_modules/express/lib/response.js:271:14)
    at ServerResponse.send (/Users/user_name/Projects/demo-node-request/node_modules/express/lib/response.js:162:21)
    at /Users/user_name/Projects/demo-node-request/server.js:112:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This is my GET method

app.get('/test', async (req, res) => {
  try {
    const response = await client.customersApi.listCustomers()
    // res.send(response.body)
    res.send(response.result)
  } catch(error) {
    console.log(error)
  }
})

The SDK sometimes returns a response that includes a value that’s a BigInt. When this response is sent to a client from the server, typically using Express, it throws an error because BigInt.prototype.toJSON doesn’t exist. MDN has a guide for working around this issue. :slight_smile: