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

Taro request 添加了异步拦截器之后, abort 丢失 #16897

Open
rotate-life opened this issue Nov 21, 2024 · 1 comment
Open

Taro request 添加了异步拦截器之后, abort 丢失 #16897

rotate-life opened this issue Nov 21, 2024 · 1 comment

Comments

@rotate-life
Copy link

相关平台

微信小程序

小程序基础库: 3.2.4
使用框架: React

复现步骤

function interceptor(chain: Taro.Chain) {
  const { requestParams } = chain
  let p: Promise<void>
  const res = new Promise<void>((resolve, reject) => {
    const timeout: ReturnType<typeof setTimeout> = setTimeout(() => {
      p = chain.proceed(requestParams)
      p
        .then((r: any) => {
          resolve(r)
        })
        .catch((err) => {
          reject(err)
        })
    }, 3000)
  })
  // @ts-ignore
  if (!isUndefined(p) && isFunction(p.abort)) res.abort = p.abort
  return res
}

const requestTask = Taro.request()

requestTask.abort()

期望结果

正常返回abort并且可以正常使用

实际结果

TypeError: requestTask.abort is not a function

环境信息

👽 Taro v3.6.17


  Taro CLI 3.6.17 environment info:
    System:
      OS: macOS 13.4.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 16.20.1 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 8.19.4 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.17 => 3.6.17 
      @tarojs/components: 3.6.17 => 3.6.17 
      @tarojs/helper: 3.6.17 => 3.6.17 
      @tarojs/plugin-framework-react: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-alipay: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-h5: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-jd: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-qq: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-swan: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-tt: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-weapp: 3.6.17 => 3.6.17 
      @tarojs/react: 3.6.17 => 3.6.17 
      @tarojs/runtime: 3.6.17 => 3.6.17 
      @tarojs/shared: 3.6.17 => 3.6.17 
      @tarojs/taro: 3.6.17 => 3.6.17 
      @tarojs/taro-loader: 3.6.17 => 3.6.17 
      @tarojs/webpack5-runner: 3.6.17 => 3.6.17 
      babel-preset-taro: 3.6.17 => 3.6.17 
      eslint-config-taro: 3.6.17 => 3.6.17 
      react: ^18.0.0 => 18.2.0 


补充信息

场景:每次发起请求前,检验token,在过期时,尝试更新一次token

This was referenced Nov 23, 2024
@rotate-life
Copy link
Author

有人吗?

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

1 participant