getResponse method
Future<T>
getResponse(
{ - bool usingCache = false,
})
Implementation
Future<T> getResponse({bool usingCache = false}) async {
Map<String, dynamic> response;
if (!usingCache) {
if (method.body.isNotEmpty || method.files.isNotEmpty) {
response = await method.request() as Map<String, dynamic>;
} else {
response = await method.requestJson() as Map<String, dynamic>;
}
} else {
String? cachedResponse =
await CacheResponseManager().getCachedResponseText(method);
if (cachedResponse == null) {
throw errorModel(cachedResponse, "NO-CACHED", ExpectType.list);
}
response = jsonDecode(cachedResponse) as Map<String, dynamic>;
}
try {
T result = fromMap(response);
if (T is ModelValidation) {
String? validateError = (result as ModelValidation).validate();
if (validateError != null) {
throw errorModel(response, validateError, ExpectType.response);
}
}
return result;
} catch (e) {
throw errorModel(response, e.toString(), ExpectType.response);
}
}