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("statusCode")) {
      result.statusCode = parsed["statusCode"] as int;
    } else {
      result.statusCode = 200;
    }
    if (parsed.containsKey("apiCode")) {
      result.apiCode = parsed["apiCode"] as int;
    }

    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.statusCode = response.statusCode;
    result.message = "network error";
  }
  return result;
}