fl-query
fl-query copied to clipboard
Global Error Handler
Is it possible to handle error globally, like onError, in QueryClient, or QueryClientProvider to handle all error from any query or any mutation,
@tsiresymila1 You can create Interceptor to handle global error.
@tsiresymila1 You can create Interceptor to handle global error.
@affansk , Do you mean, i need to make interceptor for request, but if it is not about using HTTP request inside query or mutation function ? So how? .
For now, the way that i found is about creating an InheritedWidget with parameter Function(dynamic error) OnError to wrap QueryClientProvider, and overload QueryBuilder and MutationBuilder to call this function(onError) when error was handled form them.
if you want to catch api error globally to show some toast message, etc. you have to use Interceptor. i dont think this package supports global error handling. onError like react query, graphql. may be in future it can be implemented @KRTirtho
I've found myself needing this as well, so might add it. Copying the api of https://tanstack.com/query/latest/docs/reference/QueryCache#global-callbacks would be a nice. If anyone wants to create a PR for it, it would be more than welcome. Otherwise, I can find time to add it maybe next week.