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

[Question]@uni/request Web端为什么失败也会触发success #182

Closed
cielyic opened this issue Jun 15, 2021 · 5 comments
Closed

[Question]@uni/request Web端为什么失败也会触发success #182

cielyic opened this issue Jun 15, 2021 · 5 comments

Comments

@cielyic
Copy link

cielyic commented Jun 15, 2021

背景

request({
  url: 'https://alibaba.github.io/rax/',
  method: 'POST',
  data: {
    from: 'Rax',
  },
  dataType: 'json',
  success: (res) => {
    console.log('success', res);
  },
  fail: (res) => {
    console.log('fail', res);
  },
  complete: (res) => {
    console.log('complete', res);
  },
});
  • 会返回失败

预期:

  • 只触发fail和complete

但实际

  • 触发success、fail、complete

然后我看源码
https://github.com/raxjs/universal-api/blob/master/src/packages/network/request/src/web/index.ts

image

这里遇到错误并没有return掉

@SoloJiang
Copy link
Collaborator

直接来个 PR?

@cielyic
Copy link
Author

cielyic commented Jun 15, 2021

直接来个 PR?

不会

@DOBEEE
Copy link
Collaborator

DOBEEE commented Jun 15, 2021

@uni/request@1.0.8-beta 试下

@cielyic
Copy link
Author

cielyic commented Jun 15, 2021

@uni/request@1.0.8-beta 试下

有个问题:

  • 在微信小程序,是在api调用失败的时候才走fail,正常不管什么status都是走success
  • 在web,原来没有return的原因是为了 统一这种行为嘛?

@DOBEEE
Copy link
Collaborator

DOBEEE commented Jun 16, 2021

@uni/request@1.0.9-beta 调整了所有容器的实现都增加对status的判别,可以试下

@DOBEEE DOBEEE closed this as completed Jul 7, 2021
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