BeataKr / axios-har-tracker

This library was designed for gathering HAR files from requests sent using axios
https://github.com/BeataKr/axios-har-tracker
10 stars 10 forks source link

Error while trying to stream a file #21

Open bgornicki opened 1 month ago

bgornicki commented 1 month ago

HAR tracker fails with unexpected error when trying to add file stream to the archive. It tries to stringify circular object (readable stream).

How to reproduce:

import axios from 'axios';
import {AxiosHarTracker} from 'axios-har-tracker';

(async () => {
    const axiosTracker = new AxiosHarTracker(axios);

    await axios.get('https://i.imgur.com/BMSSPFJ.jpeg', {
        responseType: 'stream'
    });
})();

It generates:

/home/bgornicki/test/.nvm/versions/node/v20.10.0/bin/node --import file:/snap/webstorm/404/plugins/nodeJS/js/ts-file-loader/node_modules/tsx/dist/loader.cjs /home/bgornicki/test/har.ts
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

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 (<anonymous>)
    at AxiosHarTracker.returnResponseObject (/home/bgornicki/test/node_modules/axios-har-tracker/src/axios-har-tracker.ts:229:79)
    at AxiosHarTracker.pushNewEntryResponse (/home/bgornicki/test/node_modules/axios-har-tracker/src/axios-har-tracker.ts:278:30)
    at AxiosHarTracker.<anonymous> (/home/bgornicki/test/node_modules/axios-har-tracker/src/axios-har-tracker.ts:122:14)
    at Generator.next (<anonymous>)
    at /home/bgornicki/test/node_modules/axios-har-tracker/dist/axios-har-tracker.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/bgornicki/test/node_modules/axios-har-tracker/dist/axios-har-tracker.js:4:12)
    at <anonymous> (/home/bgornicki/test/node_modules/axios-har-tracker/src/axios-har-tracker.ts:121:22)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Axios.request (/home/bgornicki/test/node_modules/axios/lib/core/Axios.js:45:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at <anonymous> (/home/bgornicki/test/har.ts:7:5)

Node.js v20.10.0

Process finished with exit code 1
BeataKr commented 1 month ago

Hi @bgornicki can you pls write what version of axios-har-tracker did you use?

bgornicki commented 1 month ago
"axios": "1.7.7",
"axios-har-tracker": "0.7.2",
bgornicki commented 1 month ago

@BeataKr what do you think about replacing JSON.stringify with another implementation that is capable of handling circular objects, like safe-stable-stringify?