formatBodyContent static method

String formatBodyContent(
  1. dynamic body,
  2. String contentType
)

Implementation

static String formatBodyContent(dynamic body, String contentType) {
  if (body == null) {
    return _emptyBody;
  }

  if (body is String && body.isEmpty) {
    return _emptyBody;
  }

  try {
    var bodyContent = _emptyBody;

    if (!contentType.toLowerCase().contains(_applicationJson)) {
      var bodyTemp = body.toString();

      if (bodyTemp.isNotEmpty) {
        bodyContent = bodyTemp;
      }
    } else {
      if (body is String) {
        if (body.isNotEmpty) {
          if (body.contains("\n")) {
            bodyContent = body;
          } else {
            bodyContent = parseJson(body._decodeJson());
          }
        }
      } else if (body is Stream) {
        bodyContent = _stream;
      } else {
        bodyContent = parseJson(body);
      }
    }

    return bodyContent;
  } catch (e) {
    return _parseFailedText + body.toString();
  }
}