parseResponse static method

Result parseResponse(
  1. dynamic response
)

Implementation

static Result parseResponse(response) {
  Result result = Result();
  if (response.statusCode == 200 || response.statusCode == 201) {
    final Map parsed = jsonDecode(response.body);
    if (parsed.containsKey("code")) {
      result.code = parsed["code"] as int;
    } else {
      result.code = 200;
    }
    if (parsed.containsKey("message")) {
      result.message = parsed["message"] as String;
    }
    if (parsed.containsKey("data")) {
      if (parsed["data"] is Map) {
        result.data = parsed["data"];
      } else {
        result.data = parsed;
      }
    } else {
      result.data = parsed;
    }
  } else {
    result.code = response.statusCode;
    result.message = "network error";
  }
  return result;
}