Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while trying to stream a file #21

Open
bgornicki opened this issue Oct 10, 2024 · 3 comments
Open

Error while trying to stream a file #21

bgornicki opened this issue Oct 10, 2024 · 3 comments

Comments

@bgornicki
Copy link

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
Copy link
Owner

BeataKr commented Oct 14, 2024

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

@bgornicki
Copy link
Author

"axios": "1.7.7",
"axios-har-tracker": "0.7.2",

@bgornicki
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants