xdoer / PreQuest

A Modular And Pluggable Solution For HTTP Request.
https://pre-quest.vercel.app
MIT License
87 stars 14 forks source link

1.3.6 bugs? #38

Closed lzlv312 closed 2 years ago

lzlv312 commented 2 years ago

xhr库: 如果不设置 responseType 会显示警告 The provided value 'undefined' is not a valid enum value of type XMLHttpRequestResponseType. 如果设置了 responseType: 'json' 则返回结果仍是文本。 如果请求被CancelToken中断,则会报错 Uncaught TypeError: Cannot destructure property responseText of 'undefined' or 'null'.

fetch库: config必须设置一个 header: {} ,才能设置 headers,否则会卡请求。

cache中间件:文档描述和测试用例不符,到底如何使用?

xdoer commented 2 years ago
  1. xhr 代码是拷贝的 axios 源码,之前认为某些认为判断没什么必要,看来是我天真了😥。
  2. fetch 里面不必设置 header,我看了一下文档,文档写错了。除了小程序里是 header, 其他都是 headers。你出现的这个问题,可以贴一下代码,我看一下
  3. cache 中间件文档是旧的,已经更新了。用法示例在这里

目前发了 1.3.8 版本。 xhr 库的 cancelToken 已经修复,而对于 json, 目前还没时间去可看原因(代码是直接抄的 axios,可能还有什么处理没有考虑到)。

lzlv312 commented 2 years ago

已验证 1.3.8 : xhr库:CancelToken 正常执行了,且不会报错,json 的问题,在源码里面,我看text和json执行的是同一个判断,返回的是同一个值,并没有区别 fetch库:header 不设置不会卡请求了,但是CancelToken不工作,没有效果

lzlv312 commented 2 years ago

当 Content-Type: application/json;charset=utf-8 时是不是有问题?被序列化了? image

image

lzlv312 commented 2 years ago

续上面,原来必须要手动设置 requestType: 'json',只设置请求头不行,这个和axios不一样。。。requestType和responseType在axios中默认都是json了

lzlv312 commented 2 years ago

xhr 和 miniprogram 在 timeout 时会进入 catch,而fetch却不会?也没有code,那怎么判断呢。

xdoer commented 2 years ago

已发布 1.3.10

  1. requestType 不传会默认按照 json 处理
  2. fetch 本身不支持 timeout, 可以安装 timeout 中间件来处理
lzlv312 commented 2 years ago

对,我使用的就是 timeout 中间件,说的也是它,像这样 image

xdoer commented 2 years ago

这里有个 timeout 示例: https://github.com/xdoer/PreQuest/blob/main/examples/web/src/Fetch.tsx

lzlv312 commented 2 years ago

image image image

这个有问题吗?我的意思是 我测试 在 xhr 和 小程序 它是工作正常的,fetch 只是在控制台能看到 timeout 报错,但是并不会走 catch 。

xdoer commented 2 years ago

如果没走 catch 肯定是有问题的。你把 timeout 和 errorRetry 换个位置试一下

lzlv312 commented 2 years ago

试了,放在最后可以,,, image image

lzlv312 commented 2 years ago

把 timeout 和 errorRetry 换个位置 是不行的