mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
fix(core/axios): handle un-writable error stack (#6362)
Co-authored-by: Dmitriy Mozgovoy <robotshara@gmail.com>
This commit is contained in:
committed by
GitHub
parent
d1d359da34
commit
81e0455b7b
@@ -0,0 +1,47 @@
|
||||
import Axios from "../../../lib/core/Axios.js";
|
||||
import assert from "assert";
|
||||
|
||||
describe('Axios', function () {
|
||||
describe("handle un-writable error stack", function () {
|
||||
async function testUnwritableErrorStack(stackAttributes) {
|
||||
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", stackAttributes);
|
||||
throw mockError;
|
||||
}
|
||||
try {
|
||||
await axios.request("test-url", {})
|
||||
} catch (e) {
|
||||
assert.strictEqual(e.message, "test-error")
|
||||
}
|
||||
}
|
||||
|
||||
it('should support errors with a defined but un-writable stack', async function () {
|
||||
await testUnwritableErrorStack({value: {}, writable: false})
|
||||
});
|
||||
|
||||
it('should support errors with an undefined and un-writable stack', async function () {
|
||||
await testUnwritableErrorStack({value: undefined, writable: false})
|
||||
});
|
||||
|
||||
it('should support errors with a custom getter/setter for the stack property', async function () {
|
||||
await testUnwritableErrorStack({
|
||||
get: () => ({}),
|
||||
set: () => {
|
||||
throw new Error('read-only');
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it('should support errors with a custom getter/setter for the stack property (null case)', async function () {
|
||||
await testUnwritableErrorStack({
|
||||
get: () => null,
|
||||
set: () => {
|
||||
throw new Error('read-only');
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user