handleNetworkError<T extends INetworkModel<T>, R> method

Future<IResponseModel<R?, E?>> handleNetworkError<T extends INetworkModel<T>, R>({
  1. required String path,
  2. required T parseModel,
  3. required RequestType method,
  4. required DioException error,
  5. required IResponseModel<R?, E?> onError(
    1. DioException e
    ),
  6. String? urlSuffix = '',
  7. Map<String, dynamic>? queryParameters,
  8. Options? options,
  9. Duration? expiration,
  10. dynamic data,
  11. ProgressCallback? onReceiveProgress,
  12. bool isErrorDialog = false,
  13. CancelToken? cancelToken,
  14. bool? forceUpdateDecode,
})
inherited

Manage any error according from server

R: Response Model for user want to parse T: Parser Model data: Response body

Implementation

Future<IResponseModel<R?, E?>>
    handleNetworkError<T extends INetworkModel<T>, R>({
  required String path,
  required T parseModel,
  required RequestType method,
  required DioException error,
  required IResponseModel<R?, E?> Function(DioException e) onError,
  String? urlSuffix = '',
  Map<String, dynamic>? queryParameters,
  Options? options,
  Duration? expiration,
  dynamic data,
  ProgressCallback? onReceiveProgress,
  bool isErrorDialog = false,
  CancelToken? cancelToken,
  bool? forceUpdateDecode,
}) async {
  if (!isErrorDialog ||
      _noNetworkTryCount == NetworkManagerParameters.maxRetryCount) {
    return onError.call(error);
  }

  _noNetworkTryCount = 0;
  var isRetry = false;
  await NoNetworkManager(
    context: parameters.noNetwork?.context,
    customNoNetworkWidget: parameters.noNetwork?.customNoNetwork,
    onRetry: () {
      isRetry = true;
    },
    isEnable: true,
  ).show();

  if (isRetry) {
    _noNetworkTryCount = _noNetworkTryCount + 1;

    return instance.send(
      path,
      parseModel: parseModel,
      method: method,
      data: data,
      queryParameters: queryParameters,
      options: options,
      isErrorDialog: isErrorDialog,
      urlSuffix: urlSuffix,
    );
  }

  _noNetworkTryCount = 0;
  return onError.call(error);
}