7***@qq.com
7***@qq.com
  • 发布:2024-07-25 18:41
  • 更新:2024-07-26 14:56
  • 阅读:185

【报Bug】uni.reuqest timeout 在无网络时 无效

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 14.4.1 (23E224)

第三方开发者工具版本号: idea

基础库版本号: 3.4.2

项目创建方式: CLI

CLI版本号: ~5.0.0

示例代码:
uni.request({  
                url: ajax.apiUrl + url,  
                data: data,  
                method: 'POST',  
                timeout: Number(2000),//超时时间,单位 ms  
                header: {  
                    'Content-Type': contentType,  
                    'user_session_key': login.getValue('token')  
                },  
                success: (res) => {  
                    if (200 !== res.statusCode) {  
                        if (!hideErrMsg) {  
                            uni.showToast({  
                                title: "系统繁忙,请稍后再试",  
                                icon: 'none',  
                                duration: 2000  
                            })  
                        }  
                        reject(res);  
                    } else {  
                        if (res.data.errorCode) {  
                            if(res.data.errorCode === '10009'){  
                                if (restrainDumpLogin) {  
                                    reject(res);  
                                } else {  
                                    if(globalConfig.appletCode) {  
                                        if (globalConfig.id) {  
                                            uni.navigateTo({  
                                                url: "/sub_intake/pages/login/login",  
                                            })  
                                        } else {  
                                            uni.navigateTo({  
                                                url: "/sub_intake/pages/landingGuide/landingGuide",  
                                            })  
                                        }  
                                    }else {  
                                        uni.navigateTo({  
                                            url: "/sub_intake/pages/login/login",  
                                        })  
                                    }  
                                }  
                            } else {  
                                if (!hideErrMsg) {  
                                        uni.showToast({  
                                            title: res.data.errorDetails,  
                                            icon: 'none',  
                                            duration: 2000  
                                        })  
                                    }  
                                reject(res);  
                            }  
                            throw new Error('Server Error');  
                        } else {  
                            alert.hideLoading()  
                            resolve(res);  
                        }  
                    }  
                },  
                fail: (res) => { //接口调用失败的回调  
                    console.log('请求的数据',res)  
                    uni.showToast({  
                        title: res.errMsg,  
                        icon: 'none',  
                        duration: 3000  
                    })  
                    alert.hideLoading()  
                    reject(res)  
                },  
                complete: (res)=> {  
                    if(res.errMsg.includes('request:fail')) {  
                        alert.showError('请检查网络连接');  
                    }  
                }  
            });

操作步骤:

微信小程序开启飞行模式后 等待响应

预期结果:

按照传入了timeout (2秒) 时间作出响应

实际结果:

等了几十秒才有响应结果

bug描述:

我使用uni.request 调用接口 设置timeout 超时时间
这个timeout 在我的小程序 开启飞行模式后 依然需要等待我几十秒才会有结果complete

2024-07-25 18:41 负责人:无 分享
已邀请:
蔡cai

蔡cai - 开发的插件:https://ask.dcloud.net.cn/article/41539

要回复问题请先登录注册