axios-logger
axios-logger copied to clipboard
Converting circular structure to JSON error with ts-node upgrade
Describe the bug After upgrading ts-node to 10.8.1 , there is an error reported by axios logger . The error is not seen while on earlier versions of ts-node.
Versions TS-Node: 10.8.1 Axios Logger: 2.6.1
Error Message Converting circular structure to JSON with ts-node upgrade
Error Stack
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'TLSSocket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle
at JSON.stringify (
@nagarakesh4 what is the version of ts-node you used previously? I have the same error with ts-node 10.4.0, in my case, specifically with responseType: 'stream'
Looks like the StringBuilder class does not differentiate between different payload types. Anything that is not a string it tries to jsonify. I worked around my specific case using this:
this.http.interceptors.request.use(AxiosLogger.requestLogger);
this.http.interceptors.response.use((res) => {
let data;
if (res.data instanceof IncomingMessage) {
data = res.data;
res.data = '<IncomingMessage>';
}
AxiosLogger.responseLogger(res);
if (data) {
res.data = data;
}
return res;
});
I think we should proceed with the test on that node version.