Closed KrishnaPG closed 2 years ago
I knew this problem long ago.. We add promise.reject
when throwOnError: false
, just for run().catch()
Someone need run
to rejected
when the request is error.
They think no matter what throwOnError is, run should can catch the error...
I cannot remove the promise.reject, because it's a break change..
I will fix this on next major version.
So how is the bug now?
Hello:
这个问题我们已经在 v3.0 版本彻底修复,目前 v3.0 版本已经发布 alpha 版本。
欢迎试用。
文档:https://ahooks-next.surge.sh/ 源码:https://github.com/alibaba/hooks/tree/next
安装最新分支
$ npm install --save ahooks@next
# or
$ yarn add ahooks@next
We have fixed this problem in the v3.0 version, and the alpha has been released.
Welcome to try.
Doc:https://ahooks-next.surge.sh/ Source Code:https://github.com/alibaba/hooks/tree/next
Install v3.0
$ npm install --save ahooks@next
# or
$ yarn add ahooks@next
When the
useRequest
is used as part of the umi this below code causes the application to crash due to unhandled promise rejections: https://github.com/alibaba/hooks/blob/fd6d0a442cc8d569912cb2be6a8d68d882127ce5/packages/use-request/src/useAsync.ts#L172-L175In a
umi
based application, theapp.tsx
contains a default error handler that shows error alert notifications before the useRequest hook's_run
catch handler is invoked. That is, error is already handled hence whenthrowOnError
is not true, the_run
method should not reject the promise and instead just set the error state.Problem:
throwOnError
is false or undefinedSolution:
useAsync.ts
file that are rejecting the promise. If someone needs error to be thrown, they can always setthrowOnError: true
and no need for promise rejection.The promise rejection is creating a catch-22 loop that is impossible to break. For more details, please refer to: https://github.com/umijs/umi/issues/5910