mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
docs: clarify silentJSONParsing requires explicit responseType: 'json' (#7398)
* fix: make silentJSONParsing: false work without explicit responseType Setting transitional.silentJSONParsing to false had no effect unless responseType was also explicitly set to 'json'. This was because strictJSONParsing required JSONRequested (responseType === 'json') to be true, but the default responseType is undefined. Now strictJSONParsing is also enabled when forcedJSONParsing is active (the default) and no explicit responseType is set, which matches the documented behavior that silentJSONParsing controls whether parse errors are thrown. Fixes #7253 * docs: clarify silentJSONParsing requires explicit responseType: 'json' Reverted the code change and updated docs instead — silentJSONParsing only takes effect when responseType is explicitly set to 'json', which is by design. Updated the README to make this behavior clear and show the correct usage pattern. --------- Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -624,7 +624,12 @@ These are the available config options for making requests. Only the `url` is re
|
||||
transitional: {
|
||||
// silent JSON parsing mode
|
||||
// `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
|
||||
// `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
|
||||
// `false` - throw SyntaxError if JSON parsing failed
|
||||
// Important: this option only takes effect when `responseType` is explicitly set to 'json'.
|
||||
// When `responseType` is omitted (defaults to no value), axios uses `forcedJSONParsing`
|
||||
// to attempt JSON parsing, but will silently return the raw string on failure regardless
|
||||
// of this setting. To have invalid JSON throw errors, use:
|
||||
// { responseType: 'json', transitional: { silentJSONParsing: false } }
|
||||
silentJSONParsing: true, // default value for the current Axios version
|
||||
|
||||
// try to parse the response string as JSON even if `responseType` is not 'json'
|
||||
|
||||
Reference in New Issue
Block a user