Skip to content

[useRequest] onError not catching onBefore error #177

Closed
@Airkro

Description

@Airkro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions