hg-pyun / axios-logger

Beautify Axios Logging Messages
MIT License
173 stars 33 forks source link

Converting circular structure to JSON error with ts-node upgrade #115

Open nagarakesh4 opened 2 years ago

nagarakesh4 commented 2 years ago

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)

arteme commented 2 years ago

@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 commented 2 years ago

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;
        });
hg-pyun commented 2 years ago

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