safeCallReportStatus<T> method
Future<void>
safeCallReportStatus<T>({
- required Either<
FetchFailure, BaseListResponse< response,T> ?> - required dynamic funError(),
- required dynamic funDataServer(),
- dynamic funSuccess()?,
- bool isShowError = true,
Implementation
Future<void> safeCallReportStatus<T>(
{required Either<FetchFailure, BaseListResponse<T>?> response,
required Function(FetchFailure) funError,
required Function(FetchData<List<T>>) funDataServer,
Function(FetchData<List<T>>)? funSuccess,
bool isShowError = true}) async {
try {
if (response.get != null) {
await safeResponseDataServer<List<T>>(
dataServer: response.get?.data,
funCallBack: (data) async {
if (data?.isNotEmpty == true) {
final dataEx = response.get?.data_extension;
if (funSuccess != null) {
funSuccess(FetchData<List<T>>(data: data, dataEx: dataEx));
}
return funDataServer(
FetchData<List<T>>(data: data, dataEx: dataEx));
} else {
return funError(await safeResponseError(
typeError: TypeError.ERROR_NO_DATA,
isShowError: isShowError));
}
});
} else {
return funError(await safeResponseError(
typeError: TypeError.ERROR_SERVER,
errorServer: response.leftOrCrash,
isShowError: isShowError));
}
} catch (e) {
final failure = returnFailure(e);
return funError(await safeResponseError(
typeError: TypeError.ERROR_UNKNOWN,
errorServer: FetchFailure.crashError(100, failure, "Error"),
isShowError: isShowError));
}
}