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.toJSON() should exclude TLSSocket #5190

Open
benoit-messager opened this issue Oct 26, 2022 · 2 comments
Open

Error.toJSON() should exclude TLSSocket #5190

benoit-messager opened this issue Oct 26, 2022 · 2 comments

Comments

@benoit-messager
Copy link

Describe the bug

When calling JSON.stringify(AxiosError.toJSON()) there is a circular reference error :

[TypeError: Converting circular structure to JSON
        --> starting at object with constructor 'TLSSocket'
        |     property 'parser' -> object with constructor 'HTTPParser'
        --- property 'socket' closes the circle]

The error does not occurs on all platforms.

To Reproduce

The code building the axios instance is spread amongst several classes with multiple conditions, i will try my best to summarize the configuration while keeping the code readable :

const axiosInstance = axios.create({
            httpsAgent:
                new Agent({
                    ca: this.certificate,
                }),
        });

  axiosInstance.interceptors.request.use((config: any) => {
            config.headers[correlationIdKey] = getCorrelationId();
            config.metadata = config.meta || {};
            config.metadata = { startTime: new Date() };
            return config;
        });

  axiosInstance.interceptors.response.use(
            (response: any) => {
                this.logResponse(partnerName, response, maskedFields?.responseFields);
                return response;
            },
            (error: any) => {
                this.logResponse(partnerName, error, maskedFields?.responseFields);
                return Promise.reject(error);
            }
        );

axiosInstance.get<unknown>(url)
            .catch((error: AxiosError) => {
                this.logError("getCustomer", error);  //This method use JSON.stringify(error.toJSON()) and throw the circular reference error
                throw new ApiError("NAG_4400", error.message);
            })

Code snippet

No response

Expected behavior

Calling JSON.stringify() with an axios error does not result in a circular reference error.

Axios Version

1.1.3

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

v16.15.1

OS

OSX 12.6

Additional Library Versions

No response

Additional context/Screenshots

No response

@benoit-messager
Copy link
Author

Just realize this is a duplicate of #4486

@deenairn
Copy link

This is definitely still happening in our environment, though our call stack is not the same. I've documented this at #5332, so I think this is still an active problem in some scenarios and a fix should be considered.

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