SyntaxError axios
JSON parse error not thrown on invalid response when silentJSONParsing is false due to default responseType being undefined
JavaScript 0 people found this helpful
Environment
- Library Version
- 1.13.2
- Language
- JavaScript
- Framework
- None
- Operating System
Solutions
Method 1
Explicitly set responseType to 'json' to ensure silentJSONParsing throws errors on invalid JSON
const response = await axios.get(uri, {
transitional: { silentJSONParsing: false },
responseType: 'json', // Explicitly set this to enable strict parsing
});
Alternatives
- Wait for upstream library fix merging PR
- Patch lib/defaults/index.js locally to set default responseType