'Canceling rn-fetch-blob

I ran into issues where during limited network, rnfb hangs and doesn't produce a timeout consistently. Is this a bad way to handle that?

return new Promise((res, err) => {
    let time;
    const task = RNFetchBlob.fetch(
      'PUT',
      `${API_HOST}${path}`,
      {
        'Content-Type': `image/${fileType}`,
        Authorization: `Bearer ${token}`
      },
      RNFetchBlob.wrap(file)
    );

    task
      .then((result) => {
        clearTimeout(time);
        const resCode = result.info()?.status;
        if (resCode !== 200) {
          err(new Error(`Upload delivery proof failed with status code ${resCode}`));
        }
        res(result);
      })
      .catch((e) => {
        clearTimeout(time);
        err(e);
      });

    time = setTimeout(() => {
      task.cancel();
    }, 10000);
  });


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source