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

[useRequest] onError not catching onBefore error #177

Closed
7 tasks done
Airkro opened this issue Nov 30, 2023 · 7 comments
Closed
7 tasks done

[useRequest] onError not catching onBefore error #177

Airkro opened this issue Nov 30, 2023 · 7 comments
Labels
pending triage issue: pending triage

Comments

@Airkro
Copy link

Airkro commented Nov 30, 2023

Describe the bug

throw an error in onBefore,

onError callback is not fire...

Steps to reproduce

<template>
  <button @click="run">run</button>
  <div>data: {{ JSON.stringify(data) }}</div>
  <div>error: {{ error?.message }}</div>
</template>

<script setup>
import { useRequest } from 'vue-hooks-plus';

const { data, error, run } = useRequest(async () => {
  // return anything here
}, {
  manual: true,
  onBefore() {
    // do something then
    throw new Error('example'); // remove this line everything will fine
  },
  onSuccess(result) {
    console.log('okay:', result)
  },
  onError(error) {
    console.error('inner', error);  // this line will not run, can't catch `Error: example`
  },
});
</script>

System Info

vue-hooks-plus: 1.8.6
vue: 3.3.x

Used Package Manager

npm

Validations

@Airkro Airkro added the pending triage issue: pending triage label Nov 30, 2023
@XiaoDaiGua-Ray
Copy link
Contributor

hi.
In response to your question, I have not repeated it. Can you provide more code details?

image

@Airkro
Copy link
Author

Airkro commented Dec 1, 2023

reproduce playground

@XiaoDaiGua-Ray
Copy link
Contributor

I think you're using it the wrong way, 'async () => {}' seems to be an invalid parameter, so the code doesn't work as expected.

image

@Airkro
Copy link
Author

Airkro commented Dec 1, 2023

It is just an example, and there is nothing wrong with async () => {}. an async function will return Promise<void>, it will work fine.

If you still don't understand, I make a better example

@Airkro Airkro changed the title onError not catching onBefore error [useRequest] onError not catching onBefore error Dec 1, 2023
@XiaoDaiGua-Ray
Copy link
Contributor

Got it.

It is a manual error thrown in the 'onBefore' configuration item that interrupts the entire code flow.

It seems to be a problem, which will be solved later in the discussion.

@XiaoDaiGua-Ray
Copy link
Contributor

image image

NelsonYong pushed a commit that referenced this issue Dec 24, 2023
* feat: useFullscreen hook支持默认参数。并且同步更新文档与demo。

* feat: useFullscreen新增配置defaultElement项

* fix: useFullscreen defaultElement类型提示错误修复

* docs: 更正 useDrop 文档错误

* fix: 修复在使用useRequest方法时,在onBefore配置项中手动抛出错误时会导致整个代码流程中断的问题(#177)
@NelsonYong
Copy link
Contributor

@XiaoDaiGua-Ray @Airkro Done.

version: v1.8.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending triage issue: pending triage
Projects
None yet
Development

No branches or pull requests

3 participants