onError<ResponseType, InnerType> method
ApiResponse<ResponseType, InnerType>
onError<ResponseType, InnerType>(
- ApiResponse<
ResponseType, InnerType> response
override
Intercepts the error and returns the modified error
Implementation
@override
ApiResponse<ResponseType, InnerType> onError<ResponseType, InnerType>(
ApiResponse<ResponseType, InnerType> response) {
try {
if (kDebugMode) {
// print(
// 'in convert error ${response.bodyString}, ${response.error?.runtimeType}, ${response.error?.runtimeType is ErrorModel}');
}
if (response.error != null) {
return response.copyWith(error: response.error);
}
var json = _tryDecodeJson(response.bodyString);
json = _getBody(json, response.request.error?.key);
// if ((json as Map<String, dynamic>?)?.getKey('message') is List) {
var body = _decode<ErrorType>(json);
return response.copyWith(error: body);
// }
// return response.copyWith(error: Error());
} catch (e) {
var body = _decode<ErrorType>(json);
return response.copyWith(error: body);
}
}