2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

Revert "fix: silentJSONParsing=false should throw on invalid JSON (#7253) (#7…" (#7298)

This reverts commit 7d19335e43.
This commit is contained in:
Jay
2025-12-08 14:19:20 +02:00
committed by GitHub
parent e0a120620e
commit a4230f5581
2 changed files with 2 additions and 71 deletions
-69
View File
@@ -1,69 +0,0 @@
import assert from 'assert';
import axios from '../index.js';
describe('Regression: Silent JSON Parsing', function () {
beforeEach(function () {
// Mock adapter to return invalid JSON
axios.defaults.adapter = async (config) => {
return {
data: '{ invalid json }',
status: 200,
statusText: 'OK',
headers: {},
config
};
};
});
afterEach(function () {
delete axios.defaults.adapter;
});
it('should throw SyntaxError when silentJSONParsing is false', async function () {
try {
await axios.get('/test', {
transitional: {
silentJSONParsing: false
}
});
assert.fail('Should have thrown error');
} catch (err) {
assert.ok(err.name === 'SyntaxError' || err.code === 'ERR_BAD_RESPONSE', 'Error should be SyntaxError or ERR_BAD_RESPONSE');
}
});
it('should return raw string when silentJSONParsing is true (default)', async function () {
const response = await axios.get('/test', {
transitional: {
silentJSONParsing: true
}
});
assert.strictEqual(response.data, '{ invalid json }');
});
it('should throw SyntaxError when responseType is json (legacy behavior)', async function () {
try {
await axios.get('/test', {
responseType: 'json',
transitional: {
silentJSONParsing: false
}
});
assert.fail('Should have thrown error');
} catch (err) {
assert.ok(err.name === 'SyntaxError' || err.code === 'ERR_BAD_RESPONSE', 'Error should be SyntaxError or ERR_BAD_RESPONSE');
}
});
it('should swallow error when silentJSONParsing is true and responseType is json (legacy behavior)', async function () {
const response = await axios.get('/test', {
responseType: 'json',
transitional: {
silentJSONParsing: true
}
});
assert.strictEqual(response.data, '{ invalid json }');
});
});