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

请求发生错误时怎么取消loading? #1580

Closed
liubin915249126 opened this issue Mar 29, 2018 · 9 comments
Closed

请求发生错误时怎么取消loading? #1580

liubin915249126 opened this issue Mar 29, 2018 · 9 comments

Comments

@liubin915249126
Copy link

使用dva2时dva对loading的处理很方便,但发现请求发生错误时loading没法取消,怎么解决?

@hellohejinyu
Copy link

try catch 捕获掉后这个 effects 就会结束了,然后 loading 也就结束了

@liubin915249126
Copy link
Author

要每个请求都要写吗?有没有全局的捕获方法?

@sorrycc
Copy link
Member

sorrycc commented Apr 2, 2018

试试全局写一个 onError 。

@woshiguabi
Copy link
Contributor

@sorrycc 我也遇到过这个问题,花了点功夫才找到答案,加上了一个空的onError。
我觉得还是默认加上一个onError比较好,大多数人应该都不希望出现这种情况。

@JeremyZheng
Copy link

@woshiguabi 空的onError加在哪里?

@zhilianbi520
Copy link

在app.js中添加

export const dva = {
  config: {
    onError(e) {
      e.preventDefault();
      console.error(e.message);
    },
  },
};

对吧?

@Verten
Copy link

Verten commented Feb 15, 2019

在app.js中添加

export const dva = {
  config: {
    onError(e) {
      e.preventDefault();
      console.error(e.message);
    },
  },
};

对吧?

在这个onError 中主要能处理哪些场景呢?

@Flyinginginging
Copy link

const app = dva({
onError(e) {
e.preventDefault();
Toast.offline('网络异常', 3)
},
});

@stale
Copy link

stale bot commented May 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 10, 2019
@stale stale bot closed this as completed May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants