添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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
Uncaught (in promise) useRequest has caught the exception, if you need to handle the exception yourself, you can set options.throwOnError to true.

能不能把这一句提示转成 warning
作为报错是会触发一些其他上报的

  • onError 只是单纯的钩子,无法将错误消化掉。
  • throwOnError 无论是 true/false 都会抛出 Uncaught (in promise)
  • throwOnError:false 抛出的是内置提示
  • throwOnError:true 抛出的是原始错误,可以用 run.catch() 处理。
  • 也就是说用户要是不想触发 Uncaught (in promise) ,就必须使用以下代码:

    const { run } = useRequest(fetch, { manual: true, throwOnError: true });
    run.catch(handle); // 如果使用 pollingInterval 的话,这招也会失效

    这显然是得不偿失,有必要优化一下。

    I think just return at this line would work better. No one would like to catch these errors.

    diff --git a/node_modules/@ahooksjs/use-request/es/useAsync.js b/node_modules/@ahooksjs/use-request/es/useAsync.js
    index 9783cb8..fa15271 100644
    --- a/node_modules/@ahooksjs/use-request/es/useAsync.js
    +++ b/node_modules/@ahooksjs/use-request/es/useAsync.js
    @@ -199,7 +199,7 @@ function () {
           console.error(error); // eslint-disable-next-line prefer-promise-reject-errors
    +      return;
           return Promise.reject('useRequest has caught the exception, if you need to handle the exception yourself, you can set options.throwOnError to true.');
         })["finally"](function () {
           if (currentCount === _this.count) {
    diff --git a/node_modules/@ahooksjs/use-request/lib/useAsync.js b/node_modules/@ahooksjs/use-request/lib/useAsync.js
    index 43ba293..91411e3 100644
    --- a/node_modules/@ahooksjs/use-request/lib/useAsync.js
    +++ b/node_modules/@ahooksjs/use-request/lib/useAsync.js
    @@ -221,7 +221,7 @@ function () {
           console.error(error); // eslint-disable-next-line prefer-promise-reject-errors
    +      return;
           return Promise.reject('useRequest has caught the exception, if you need to handle the exception yourself, you can set options.throwOnError to true.');
         })["finally"](function () {
           if (currentCount === _this.count) {
    $ 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
    $ yarn add ahooks@next