-
If I want to handle errors further up the stack I don't get much context about which query had the error. new QueryClient({
defaultOptions: {
queries: { onError: (err) => { /* no idea what triggered this error */ } },
mutations: { onError: (err) => { /* no idea what triggered this error */ } },
},
}) If the query key was provided as a second argument then I could use that to make better decisions and/or report errors with more context. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
for this use case (global error handling) you can (and likely should) use the global callbacks on the queryCache instead of I've gone into details here: https://tkdodo.eu/blog/react-query-error-handling not only will the global callbacks only be called once per cache entry (rather than once per observer), they also get the whole see also: |
Beta Was this translation helpful? Give feedback.
for this use case (global error handling) you can (and likely should) use the global callbacks on the queryCache instead of
defaultOptions
.I've gone into details here: https://tkdodo.eu/blog/react-query-error-handling
not only will the global callbacks only be called once per cache entry (rather than once per observer), they also get the whole
query
/mutation
passed as second parameter.see also: