Open yooneskh opened 3 weeks ago
You can create a customized fetch instance and do the global error handling in the onResponseError
hook. Then you use that custom fetch in your app
https://nuxt.com/docs/guide/recipes/custom-usefetch#custom-fetch
@MuhammadM1998 thank you for replying. The issue with onResponseError
is that it does not halt the execution of the code (like throwing does). Also, without the global catch
ing of the errors, the errors will be shown in the console which I like to avoid.
Environment
Build Modules: -
Reproduction
Describe the bug
How is it possible to catch
$fetch
errors globally? As you can see in my repro, i have api calls which I want to proceed only if the call has succeeded, and I want the$fetch
errors from everywhere to be handled in one place. I thought this would workBut it does not (for
$fetch
, it works for other things).NuxtErrorBoundary
does not work too.And if I give an
onResponseError
to the$fetch
, although it gives me the error, but it does not halt execution, like throwing.Is there any workaround?
Additional context
No response
Logs
No response