onResponse<ResponseType, InnerType> method
ApiResponse<ResponseType, InnerType>
onResponse<ResponseType, InnerType>(
- ApiResponse<
ResponseType, InnerType> response
override
Intercepts the response and returns the modified response
Implementation
@override
ApiResponse<ResponseType, InnerType> onResponse<ResponseType, InnerType>(
ApiResponse<ResponseType, InnerType> response) {
Pagination? pagination;
if (kDebugMode) {
print(
'in convert response ${response.statusCode} ${response.bodyString.runtimeType}, ${response.bodyString}');
}
var jsn = _tryDecodeJson(response.bodyString);
// if (response.request.hasPagination) {
// try {
// pagination = _decode<m.Pagination>(_getBody(jsn, 'meta'));
// } catch (e) {
// if (kDebugMode) {
// print(e);
// }
// }
// }
// if (jsn['status'] == false) return onError(response);
if (response.request.nestedKey != null &&
(response.request.nestedKey?.isNotEmpty ?? false)) {
jsn = _getBody(jsn, response.request.nestedKey);
}
if (kDebugMode) print('in convert response ${jsn.runtimeType}, $jsn');
try {
final body = _decode<InnerType>(_getBody(jsn, response.request.dataKey));
if (kDebugMode) print(body?.toString());
return response.copyWith(body: body, pagination: pagination);
} catch (e, _) {
if (kDebugMode) {
print(e);
print('error, $_');
}
return response.copyWith(body: null, pagination: pagination);
}
// pagination: pagination);
}