【问题标题】:Error: canceled due to java.lang.IllegalStateException: cannot make a new request because the previous response is still open错误:由于 java.lang.IllegalStateException 而被取消:无法发出新请求,因为之前的响应仍处于打开状态
【发布时间】:2022-12-23 15:18:37
【问题描述】:

我正在尝试从 url 下载 zip,但 RNFetchBlob 告诉我我有一个先前的响应待处理并使应用程序崩溃。

这是我调用 fetch 的函数

  const downloadFile = async () => {
  const dirs = RNFetchBlob.fs.dirs;

  const response = await RNFetchBlob.config({
    fileCache: true,
    appendExt: 'zip',
    path: dirs.DownloadDir + '/files/icons.zip',
    addAndroidDownloads: {
      title: dirs.DownloadDir + '/files/icons.zip',
      description: `Download ${dirs.DownloadDir + '/files/icons.zip'}`,
      useDownloadManager: false,
      notification: false,
    },
  }).fetch('GET', BASE_URL + 'iconos');

  console.log(response.path());
  console.log(response);
  return response;
};

在这里我检查权限

const checkPermission = async () => {
  if (Platform.OS === 'ios') {
    const response = await downloadFile();
    return response;
  } else {
    try {
      const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
        {
          title: 'Storage Permission Required',
          message: 'Application needs access to your storage to download File',
        },
      );
      if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        // Start downloading
        const response = await downloadFile();
        console.log('Storage Permission Granted.');
        return response;
      } else {
        // If permission denied then show alert
        Alert.alert('Error', 'Storage Permission Not Granted');
      }
    } catch (err) {
      // To handle permission related exception
      console.log('++++' + err);
    }
  }
};

这是我的 redux reducer

export const getIcons = () => {
  return async dispatch => {
    dispatch(fetching());
    try {
      const response = await checkPermission();
      dispatch(getResponseSuccess(response));
    } catch (error) {
      dispatch(getResponseFailure());
    }
  };
};

当应用程序在 checkPermission 中执行下载文件时捕获并出现错误

++++错误:由于java.lang.IllegalStateException而取消:无法发出新请求,因为先前的响应仍然打开:请 调用 response.close()

【问题讨论】:

  • 你有什么解决方法吗?

标签: javascript reactjs react-native react-redux redux-toolkit


【解决方案1】:

我在我的 react-native 中遇到了这个错误。有解决办法吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 2021-09-24
    • 2019-11-09
    • 2012-10-18
    • 1970-01-01
    相关资源
    最近更新 更多