safeCallReportStatus<T> method

Future<void> safeCallReportStatus<T>({
  1. required Either<FetchFailure, BaseListResponse<T>?> response,
  2. required dynamic funError(
    1. FetchFailure
    ),
  3. required dynamic funDataServer(
    1. FetchData<List<T>>
    ),
  4. dynamic funSuccess(
    1. FetchData<List<T>>
    )?,
  5. 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));
  }
}