T
TanStack7mo ago
extended-salmon

Tanstack (vue) query throws error regardless of the throwOnError property

I've been trying to set up my Vue Query mutations so that errors are handled within the onError callback. However, instead of being caught there, the errors propagate to the root of my application, causing the Nuxt framework to display its error page. How to fix that?
No description
No description
3 Replies
extended-salmon
extended-salmonOP7mo ago
adding images of my vue query config and example of mutation
extended-salmon
extended-salmonOP7mo ago
if i call this function without try/catch block it throws Nuxt error causing application to crash which I don't want, I want to trigger onError callback which shows toast message based on the HTTP error code if i call this function with the try/catch it works as expected but I don't want to wrap each mutation within the try catch block
No description
correct-apricot
correct-apricot7mo ago
mutateAsync throws by default, cause you are awaiting promise. It has to either resolve or reject, and we should not swallow the error in that case. I believe you want to use mutate which should respect throwOnError.

Did you find this page helpful?