-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Description
Since Axios v1.12.0, AxiosError objects contain circular references that cause JSON.stringify() to fail with "Converting circular structure to JSON" errors.
Root Cause
PR #6982 introduced the cause property that chains the original error:
javascript
if (error && axiosError.cause == null) {
Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
}
The original error objects often contain circular references (e.g., network errors with socket references), which are now preserved in the AxiosError, making the entire error object unstringifiable.
To Reproduce
javascript
const axios = require('axios');
// Trigger a network error
axios.get('http://nonexistent-domain.invalid')
.catch(error => {
console.log(JSON.stringify(error)); // Throws: Converting circular structure to JSON
});
Expected behavior
AxiosError objects should be serializable with JSON.stringify() for logging purposes, as they were in v1.11.0 and earlier.
Environment
- Axios version: 1.12.0, 1.12.1, 1.12.2
- Node.js version: Any
- Last working version: 1.11.0
Suggested Fix
The cause property should either:
- Be made non-enumerable to exclude it from JSON serialization
- Have circular references cleaned before assignment
- Implement a custom
toJSON()method that handles circular references
Impact
This breaks logging systems that stringify error objects, causing application crashes in production environments.