mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
JSON improvements: throw if JSON parsing failed; number, boolean can be passed directly as payload for encoding to JSON #2613, #61, #907 (#3688)
* Draft * Added support for primitive types to be converted to JSON if the request Content-Type is 'application/json'; Added throwing SyntaxError if JSON parsing failed and responseType is json; Added transitional option object; Added options validator to assert transitional options; Added transitional option `silentJSONParsing= true` for backward compatibility; Updated README.md; Updated typings; * Fixed isOlderVersion helper; Fixed typo; Added validator.spec.js; * Added forcedJSONParsing transitional option #2791 * `transformData` is now called in the default configuration context if the function context is not specified (for tests compatibility); * Added `transitional.clarifyTimeoutError` to throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts; Added support of onloadend handler if available instead of onreadystatechange; Added xhr timeout test; Fixed potential bug of xhr adapter with proper handling timeouts&errors (FakeXMLHTTPRequest failed to handle timeouts);
This commit is contained in:
@@ -458,6 +458,19 @@ These are the available config options for making requests. Only the `url` is re
|
||||
// - Node only (XHR cannot turn off decompression)
|
||||
decompress: true // default
|
||||
|
||||
// transitional options for backward compatibility that may be removed in the newer versions
|
||||
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')
|
||||
silentJSONParsing: true; // default value for the current Axios version
|
||||
|
||||
// try to parse the response string as JSON even if `resposeType` is not 'json'
|
||||
forcedJSONParsing: true;
|
||||
|
||||
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
||||
clarifyTimeoutError: false;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user