getResponse method
Future<TResponse?>
getResponse(
)
Implementation
Future<TResponse?> getResponse() async {
var resp = await _fetch();
while (resp.statusCode.between(300, 400)) {
var newMethod = resp.statusCode == 303 ? HttpMethod.get : null;
var newUri = _getLocation(resp.headers)?.split(',').first.trim();
if (newUri == null || newUri.isEmpty) {
throw HttpError(
message: "The server indicated a redirect without a location.",
uri: requestConfig.url,
statusCode: resp.statusCode,
);
}
resp = await _fetch(
overrideUrl: newUri,
overrideMethod: newMethod,
);
}
if (resp.statusCode >= 400) {
throw HttpError(
message: "The request returned a ${resp.statusCode} HTTP status code"
" ${_getReason(resp)}",
uri: requestConfig.url,
statusCode: resp.statusCode,
);
}
return requestConfig.fromJson(
jsonDecode(utf8.decode(resp.bodyBytes)) as Map<String, dynamic>,
);
}