Javascript 如何修复:';10000毫秒后无法从端口()连接到(URL)';

Javascript 如何修复:';10000毫秒后无法从端口()连接到(URL)';,javascript,reactjs,react-native,promise,async-await,Javascript,Reactjs,React Native,Promise,Async Await,我正在构建一个React本机应用程序,在下载一些图像时遇到了一个问题。问题是,在成功下载了几张图片后,我遇到了一个错误 10000ms后,/10.0.3.15中的[Unhandled promise rejection:错误:未能连接到javatrade.maniatest.win/ip地址] 我认为问题来自于我的代码,我试着记录了好几次,但问题仍然存在 constructor(props) { super(props); this.state = { downl

我正在构建一个React本机应用程序,在下载一些图像时遇到了一个问题。问题是,在成功下载了几张图片后,我遇到了一个错误

10000ms后,/10.0.3.15中的[Unhandled promise rejection:错误:未能连接到javatrade.maniatest.win/ip地址]

我认为问题来自于我的代码,我试着记录了好几次,但问题仍然存在

constructor(props) {
    super(props);
    this.state = {
        downloadImages: [],
        arrLength: 0,
        progress: 0
    };
}

componentWillMount = async() => {
    axios.post('apilink')
        .then(async (response) => {
            await this.setState({ downloadImages: response.data.images, arrLength: response.data.images.length });
        })
        .finally(async() => {
            this.startDownloading();
        })
}

startDownloading = async() => {
    for(let i = 0; i < this.state.downloadImages.length; i++){
        await this.processArray(this.state.downloadImages[i])
    }

    console.log('Finished');
}

processArray = async(el) => {
    const { progress, arrLength } = this.state;
    this.setState({ progress: progress + (1/arrLength) });
    await new Promise(async(resolve) => {
        const name = el.split('/').pop();
        const imageInfo = await FileSystem.getInfoAsync(`${FileSystem.documentDirectory}allImages/files/${name}`);
        if(imageInfo.exists) {
            console.log('Already exists');
            return resolve();
        } else {
            await FileSystem.downloadAsync(el, `${FileSystem.documentDirectory}allImages/files/${name}`);
            console.log('Finished downloading');
            return resolve();
        }
    })
}
构造函数(道具){
超级(道具);
此.state={
下载图像:[],
长度:0,
进展:0
};
}
componentWillMount=async()=>{
axios.post('apilink')
。然后(异步(响应)=>{
等待此.setState({downloadImages:response.data.images,arrLength:response.data.images.length});
})
.finally(异步()=>{
这是.startDownloading();
})
}
StartDownload=async()=>{
for(设i=0;i{
const{progress,arrLength}=this.state;
this.setState({progress:progress+(1/arrLength)});
等待新承诺(异步(解析)=>{
const name=el.split('/').pop();
const imageInfo=await FileSystem.getInfoAsync(`${FileSystem.documentDirectory}allImages/files/${name}`);
如果(imageInfo.exists){
log('已经存在');
返回resolve();
}否则{
等待FileSystem.downloadsync(el,`${FileSystem.documentDirectory}allImages/files/${name}`);
log('Finished downloading');
返回resolve();
}
})
}
因此,我希望这个组件能够从API提供的链接下载图像(大约有50个)。有时我下载3然后承诺错误发生,有时我下载12并且承诺错误发生我不确定我做错了什么

以下是console.log中错误的图片链接