mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Release/0.21.4 (#4025)
* fix json transform when data is pre-stringified (#4020) * [Updating] incorrect JSON syntax in README.md * [Releasing] v0.21.4 Co-authored-by: Guillaume FORTAINE <guillaume+github@fortaine.com>
This commit is contained in:
+16
-1
@@ -26,6 +26,21 @@ function getDefaultAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
function stringifySafely(rawValue, parser, encoder) {
|
||||
if (utils.isString(rawValue)) {
|
||||
try {
|
||||
(parser || JSON.parse)(rawValue);
|
||||
return utils.trim(rawValue);
|
||||
} catch (e) {
|
||||
if (e.name !== 'SyntaxError') {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (encoder || JSON.stringify)(rawValue);
|
||||
}
|
||||
|
||||
var defaults = {
|
||||
|
||||
transitional: {
|
||||
@@ -58,7 +73,7 @@ var defaults = {
|
||||
}
|
||||
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
|
||||
setContentTypeIfUnset(headers, 'application/json');
|
||||
return JSON.stringify(data);
|
||||
return stringifySafely(data);
|
||||
}
|
||||
return data;
|
||||
}],
|
||||
|
||||
Reference in New Issue
Block a user