fix(core): serialize custom properties in AxiosError.toJSON (#6511)#7540
Open
sudip-kumar-prasad wants to merge 2 commits intoaxios:v1.xfrom
Open
fix(core): serialize custom properties in AxiosError.toJSON (#6511)#7540sudip-kumar-prasad wants to merge 2 commits intoaxios:v1.xfrom
sudip-kumar-prasad wants to merge 2 commits intoaxios:v1.xfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses #6511 by ensuring custom properties attached via AxiosError.from(..., customProps) are included when serializing an AxiosError through toJSON(), improving compatibility with JSON-based loggers.
Changes:
- Updated
AxiosError.toJSON()to include enumerable own properties from the error instance (excludingrequest,response, andcause). - Added a regression test verifying custom properties are present in the JSON output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/core/AxiosError.js | Extends toJSON() to include instance-owned enumerable properties as “custom props” while excluding certain non-serializable fields. |
| test/specs/core/AxiosError.spec.js | Adds a unit test to assert customProps passed to AxiosError.from appear in toJSON() output. |
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 3/5
- There is a concrete regression risk in
lib/core/AxiosError.js: spreadingcustomPropslast can overwrite the sanitizedconfig, which may bring back circular JSON serialization failures. - Given the high severity/confidence (7/10, 9/10) and direct runtime impact, this is more than a minor cleanup issue and raises moderate merge risk.
- Pay close attention to
lib/core/AxiosError.js- property merge order may undo sanitization and trigger serialization errors.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/core/AxiosError.js">
<violation number="1" location="lib/core/AxiosError.js:67">
P1: Spreading `customProps` last overrides sanitized `config` and can reintroduce circular JSON serialization failures.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
27ee1cf to
9d7dd10
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6511
When using
AxiosError.from(...), it's possible to passcustomPropswhich are merged onto the error instance. However, if the error was serialized viaAxiosError.toJSON(), those custom properties were completely omitted from the output. This affected users attempting to log AxiosError objects using JSON-based loggers like Pino.This PR updates
AxiosError.toJSON()to spread any enumerable own properties of the error instance into the resulting JSON object.request,response, andcauseare intentionally excluded to prevent circular reference errors or serializing raw Error instances.Important Changes
AxiosError.prototype.toJSONto dynamically capture custom properties.Testing
npm run test:node) pass successfully.npm run test:package) pass successfully.Summary by cubic
Serialize custom properties in
AxiosError.toJSON()so fields fromAxiosError.from()are kept in JSON and show up in loggers. Spread custom props before standard fields so canonical error fields always win. Fixes #6511.Description
toJSON()to include own enumerable properties and excluderequest,response, andcause.message,name, etc.) to prevent overrides.AxiosError.from(...)were dropped, hiding context like request/trace IDs in logs.Errorserialization.Docs
No docs changes.
Testing
test/specs/core/AxiosError.spec.jsto assert custom props appear intoJSON()output.Written for commit fceca01. Summary will update on new commits.