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

处理超时的最佳实践? #14

Closed
yesmeck opened this issue Jan 9, 2019 · 4 comments
Closed

处理超时的最佳实践? #14

yesmeck opened this issue Jan 9, 2019 · 4 comments

Comments

@yesmeck
Copy link
Contributor

yesmeck commented Jan 9, 2019

  1. 现在超时会调用的话会走到 errorHandler,那么我要在 errorHandler 里怎么判断这是超时错误?我现在是根据 error.message 里的 timeout,这样感觉不靠谱。
  2. 现在超时触发后,如果请求回来了,这个请求的 Promise 还是会被 resolve。这个很奇怪,超时时应该已经 reject 掉了,为什么还会再 resolve?
@yesmeck
Copy link
Contributor Author

yesmeck commented Jan 9, 2019

第二个问题是超时触发后,请求回来的时候拦截器还是会被调用。

@clock157
Copy link
Contributor

clock157 commented Jan 9, 2019

  1. request 会 export 一个内置的 RequestError ,instanceOf 这个 error.
  2. 你用 errorHandler,如果没有主动 throw Error, 相对于 response 返回 undefined。
  3. 超时还触发 response 拦截器算是 Bug.

超时我项目中没有应用过,要不 repo 给下,一起探寻下最佳实践~

@yesmeck
Copy link
Contributor Author

yesmeck commented Jan 14, 2019

看起来没什么问题了。。。

@yesmeck yesmeck closed this as completed Jan 14, 2019
@vdfor
Copy link

vdfor commented Dec 17, 2019

  1. request 会 export 一个内置的 RequestError ,instanceOf 这个 error.

建议将 RequestError 加入 ts 类型定义

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

3 participants