Coder Social home page Coder Social logo

Comments (13)

xdoer avatar xdoer commented on May 18, 2024

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

from prequest.

itmanyong avatar itmanyong commented on May 18, 2024

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

from prequest.

xdoer avatar xdoer commented on May 18, 2024

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

from prequest.

xdoer avatar xdoer commented on May 18, 2024

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

from prequest.

itmanyong avatar itmanyong commented on May 18, 2024

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

from prequest.

xdoer avatar xdoer commented on May 18, 2024

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

from prequest.

itmanyong avatar itmanyong commented on May 18, 2024

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

from prequest.

itmanyong avatar itmanyong commented on May 18, 2024

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

from prequest.

xdoer avatar xdoer commented on May 18, 2024

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

测试过程如下:

<!---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

from prequest.

itmanyong avatar itmanyong commented on May 18, 2024

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

测试过程如下:

<!---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设置就可以一致,貌似上面的响应拦截也是由于这个导致

from prequest.

xdoer avatar xdoer commented on May 18, 2024

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

from prequest.

itmanyong avatar itmanyong commented on May 18, 2024

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

感觉可以兼容一下

from prequest.

xdoer avatar xdoer commented on May 18, 2024

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

from prequest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.