Closed xiexingen closed 4 years ago
1.配置全局onError后,如果具体页面调用的时候没有则走的全局的onError
目前就是这样的
2.如果页面级别使用useRequest的时候配置了onError,那么走的是页面里面配置的onError
目前就是这样的
3.当走了onError的时候,不应该还能执行到then里面去
run().catch().then()
useRequest 内部 catch 了异常,但是 catch 自己会返回一个 Promise,触发 then。
如果我们手动 return Promise.reject()
,可能是一个 break change~
我这边跑出来的结果确实是这样的
codesandbox不咋会玩 建了一个demo,打了几个debug 可以在调试模式下看步骤 代码地址: https://codesandbox.io/s/github/xiexingen/demo-umi-hooks/tree/master/?file=/src/demo.tsx
你说的是对的,我需要想下怎么解决的。
看到有个throwOnError 是不是通过配置throwOnError:true来实现这个
看到有个throwOnError 是不是通过配置throwOnError:true来实现这个
坐等第二种形式的包,到时候我再试试
已发布。
收到 试过了 蛮香的 有个其他的问题 阿里源居然没找到2.1.0版本
I am using it as below and do not want to handle the errors manually. What is the solution?
I am getting the error: ...Uncaught (in promise) useRequest has caught the exception...
import { useRequest } from 'umi';
const { data, error, loading } = useRequest(getData, { });
if (error)
return <div>Failed to Load Data</div>;
if (loading) {
return <div>loading...</div>;
}
return <div>Username: {data}</div>;
If I use throwOnError: true
how to catch the error (I am not using manual:true
, so run
is not available).
Ideally useRequest
should take care of the error handling (notification alert) and should not complain a warning when throwOnError: false
I am using it as below and do not want to handle the errors manually. What is the solution?
I am getting the error:
...Uncaught (in promise) useRequest has caught the exception...
import { useRequest } from 'umi'; const { data, error, loading } = useRequest(getData, { }); if (error) return <div>Failed to Load Data</div>; if (loading) { return <div>loading...</div>; } return <div>Username: {data}</div>;
If I use
throwOnError: true
how to catch the error (I am not usingmanual:true
, sorun
is not available).Ideally
useRequest
should take care of the error handling (notification alert) and should not complain a warning whenthrowOnError: false
I think should pass onError function useRequest(getData,{ onError:()=>{ // TODO something } })
Thank you @xiexingen The onError
does not help when the promise is rejected. More details are here: https://github.com/alibaba/hooks/issues/812
经测试发现如下问题
1.9.2版本的时候 全局配置过UseAPIProvider的onError来进行全局的异常处理 当在实际页面调用的时候,如下代码所示 run(values, id).then(() => { handleBack(); }); 这种形式,个人感觉 如果异常了不应该再继续执行到then(目前是异常了还是会进入到then里面) 断点调试截图:
1.9.3版本里面 全局配置的UseAPIProvider里面的onError压根就不生效了
个人观点 1.配置全局onError后,如果具体页面调用的时候没有则走的全局的onError 2.如果页面级别使用useRequest的时候配置了onError,那么走的是页面里面配置的onError 3.当走了onError的时候,不应该还能执行到then里面去