Hi Rudderstack team, we’re a few requests from our...
# support
i
Hi Rudderstack team, we’re a few requests from our node SDK failing with “Error: Bad Request”
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
i
This seems to be an intermitten issue, is there a way I can see what’s causing these bad requests in the dashboard?
This is using the Node SDK @rudderstack/rudder-sdk-node”: “^2.0.2”
q
You can go to live events and check the error details
i
I’ve already checked in there, and it doesn’t show any errors
q
there should be more to the error, can you share a screenshot and payload that you see
i
The error is happening within the flush in the SDK, and it doesn’t log anything else Adding in a custom error handler now to try and pull the full payload
Ok, got some extra logging in and the error is Invalid JSON
b
Hey, @incalculable-winter-14072 is it possible to capture and share the request body?
i
Hey @bright-energy-18897, this is no longer happening and the logs I managed to capture didn’t include the request body 😢 Let me send you the full log in a DM
b
I have the same issue when I call this for example
client.identify({userId: userId});
client.track(
{event: "Order Completed",
userId: userId,
properties: {XXX}
})
await client.flush()
“node_modules/@rudderstack/rudder-sdk-node”: { “version”: “2.0.2"} error
2023-06-20T19:18:21.089Z [Rudder] error: Response error status: 400
Response error code: undefined
2023-06-20T19:18:21.090Z [Rudder] error: Error: Bad Request
/node_modules/@rudderstack/rudder-sdk-node/index.js:768
var error = new Error(err.response.statusText);
^
Error: Bad Request
at /node_modules/@rudderstack/rudder-sdk-node/index.js:768:33
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v19.5.0
c
Hello, You can pass an instance of axios http client as loadOption, property name is "axiosInstance", with interceptors to assist debugging and use any logic you like in order to debug. As example:
Copy code
const axiosInstanceWithInterceptors = axios.create();
axiosInstanceWithInterceptors.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    if(error.response.status === 400) {
      console.log(error.config.url)
      console.log(error.config.headers)
      console.log(error.config.data)
    }
    return Promise.reject(error);
  });

const analyticsClient = new Rudderanalytics(writeKey, {
  axiosInstance: axiosInstanceWithInterceptors,
  dataPlaneUrl: dataPlaneUrl,
  gzip: false,
  logLevel: 'debug',
});
Axios interceptors docs for the used version in case you need them at https://github.com/axios/axios/tree/v0.26.0#interceptors
Please let me know if this helps or you need another solution
b
Following up in case anyone else runs into this issue. I had “flushAt” set too low so that when I was trying to manually flush (await client.flush()) there was nothing to flush and therefore it errored out.
🙏 2
g
Thank you for posting the solution @better-hair-94570 for the community