formatBody static method
Implementation
static String formatBody(dynamic body, String contentType) {
try {
if (body == null) {
return _emptyBody;
}
var bodyContent = _emptyBody;
if (!contentType.toLowerCase().contains(_applicationJson)) {
var bodyTemp = body.toString();
if (bodyTemp.length > 0) {
bodyContent = bodyTemp;
}
} else {
if (body is String && body.contains("\n")) {
bodyContent = body;
} else {
if (body is String) {
if (body.length != 0) {
//body is minified json, so decode it to a map and let the encoder pretty print this map
bodyContent = _parseJson(_decodeJson(body));
}
} else if (body is Stream) {
bodyContent = _stream;
} else {
bodyContent = _parseJson(body);
}
}
}
return bodyContent;
} catch (exception) {
return _parseFailedText + body.toString();
}
}