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

fix(core/axios): handle un-writable error stack #6362

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/core/Axios.js
Expand Up @@ -51,7 +51,11 @@ class Axios {
err.stack = stack;
// match without the 2 top stack lines
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
err.stack += '\n' + stack
try {
err.stack += '\n' + stack
} catch (e) {
// ignore the case where "stack" is an un-writable property
}
}
}
alexandre-abrioux marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
20 changes: 20 additions & 0 deletions test/unit/core/Axios.js
@@ -0,0 +1,20 @@
import Axios from "../../../lib/core/Axios.js";
import assert from "assert";


describe('Axios', function () {
it('should support errors with un-writable stack', async function () {
const axios = new Axios({});
// mock axios._request to return an Error with an un-writable stack property
axios._request = () => {
const mockError = new Error("test-error");
Object.defineProperty(mockError, "stack", {value: {}, writable: false});
throw mockError;
}
try {
await axios.request("test-url", {})
} catch (e) {
assert.strictEqual(e.message, "test-error")
}
})
});