axios-logger icon indicating copy to clipboard operation
axios-logger copied to clipboard

Converting circular structure to JSON error with ts-node upgrade

Open nagarakesh4 opened this issue 3 years ago • 3 comments

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 () at StringBuilder.makeData (/node_modules/axios-logger/src/common/string-builder.ts:67:9) at responseLogger (/node_modules/axios-logger/src/logger/response.ts:20:10)

nagarakesh4 avatar Sep 08 '22 18:09 nagarakesh4

@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'

arteme avatar Sep 09 '22 20:09 arteme

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;
        });

arteme avatar Sep 09 '22 20:09 arteme

I think we should proceed with the test on that node version.

hg-pyun avatar Sep 11 '22 02:09 hg-pyun