Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

错误重试中间件貌似次数限制未起作用?? #31

Closed
itmanyong opened this issue Aug 7, 2021 · 13 comments
Closed

错误重试中间件貌似次数限制未起作用?? #31

itmanyong opened this issue Aug 7, 2021 · 13 comments

Comments

@itmanyong
Copy link

情况:创建prerequest实例,只挂载错误重试中间件,中间件具体配置如下,但是请求之后貌似一直再重试。
image
image

@xdoer
Copy link
Owner

xdoer commented Aug 7, 2021

能弄个仓库,复现一下吗?

@itmanyong
Copy link
Author

这有个简单的示例,无限循环请求。https://codesandbox.io/s/quiet-violet-duepv?file=/src/App.js

@xdoer
Copy link
Owner

xdoer commented Aug 7, 2021

感谢,找到原因所在了,等我修复一下,发一个版本。

@xdoer
Copy link
Owner

xdoer commented Aug 7, 2021

@itmanyong 已经修复了,要重新装一下安装包,或者你直接在你代码里,新建个文件,把代码https://github.com/xdoer/PreQuest/blob/main/packages/error-retry/src/index.ts粘贴过去用

@itmanyong
Copy link
Author

itmanyong commented Aug 7, 2021

版本:"@prequest/interceptor": "^1.0.3"、"@prequest/miniprogram": "^1.0.3"
情况:按照文档例子,响应拦截器貌似拦截不了,成功的请求拦截其中完全拦截不了,仿佛没有进入。如下图所示,请求成功了,但没有进入响应拦截。甚至在请求完成后我也无法拿到数据。
image
image
image
image
image

@xdoer
Copy link
Owner

xdoer commented Aug 7, 2021

拦截器有注册到中间件吗?

@itmanyong
Copy link
Author

令我无法理解的是:同样是创建的实例同一个接口,一个可以拿到数据而封装导出的缺无法拿到数据!!!
1.封装实例,直接导出,不做任何中间件处理
image
image
image
image

@itmanyong
Copy link
Author

拦截器有注册到中间件吗?
拦截器已注册到中间件,控制台也打印了请求拦截的配置。就是响应拦截未有响应。

@xdoer
Copy link
Owner

xdoer commented Aug 7, 2021

我这边测试结果是没问题的。

测试过程如下:

<!---demo.ts---->

import { create } from '@prequest/miniprogram'
import Taro from '@tarojs/taro'

const prequestInstance = create(Taro.request, {
  baseURL: 'http://localhost:8000'
})

export default prequestInstance

页面文件

import { View } from '@tarojs/components'
import preInstance from '@common/demo'
import { create } from '@prequest/miniprogram'
import Taro from '@tarojs/taro'

export default function () {

  function common() {
    preInstance.post('/token').then(res => {
      console.log('查看响应1', res)
    })
    create(Taro.request).post('http://localhost:8000/token').then(res => {
      console.log('查看响应2', res)
    })
  }

  return (
    <View>
      <View onClick={common}>普通请求</View>
    </View>
  )
}

响应如下:
image

@itmanyong
Copy link
Author

itmanyong commented Aug 7, 2021

我这边测试结果是没问题的。

测试过程如下:

<!---demo.ts---->

import { create } from '@prequest/miniprogram'
import Taro from '@tarojs/taro'

const prequestInstance = create(Taro.request, {
  baseURL: 'http://localhost:8000'
})

export default prequestInstance

页面文件

import { View } from '@tarojs/components'
import preInstance from '@common/demo'
import { create } from '@prequest/miniprogram'
import Taro from '@tarojs/taro'

export default function () {

  function common() {
    preInstance.post('/token').then(res => {
      console.log('查看响应1', res)
    })
    create(Taro.request).post('http://localhost:8000/token').then(res => {
      console.log('查看响应2', res)
    })
  }

  return (
    <View>
      <View onClick={common}>普通请求</View>
    </View>
  )
}

响应如下:
image

我尝试了你的例子没有问题,加上responseType:json之后就不可以; 你试一下呢,我反复尝试了几次,确实是注销; responseType设置就可以一致,貌似上面的响应拦截也是由于这个导致

@xdoer
Copy link
Owner

xdoer commented Aug 7, 2021

Taro 的 responseType 不支持 json,传了导致响应不了,用原始的 Taro.request 请求也一样。

@itmanyong
Copy link
Author

Taro 的 responseType 不支持 json,传了导致响应不了,用原始的 Taro.request 请求也一样。

感觉可以兼容一下

@xdoer
Copy link
Owner

xdoer commented Aug 7, 2021

请求库层面兼容不了,因为本质上是通过 success 和 fail 回调函数,来判断请求成功与否,如果 Taro.request 没有响应,请求库层面就会认为一直处于请求的过程中。。这个只能给 Taro 提 RP 了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants