fl-query icon indicating copy to clipboard operation
fl-query copied to clipboard

Global Error Handler

Open tsiresymila1 opened this issue 1 year ago • 4 comments

Is it possible to handle error globally, like onError, in QueryClient, or QueryClientProvider to handle all error from any query or any mutation,

tsiresymila1 avatar Jan 18 '24 13:01 tsiresymila1

@tsiresymila1 You can create Interceptor to handle global error.

affansk avatar Jan 23 '24 13:01 affansk

@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.

tsiresymila1 avatar Jan 23 '24 13:01 tsiresymila1

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

affansk avatar Jan 24 '24 14:01 affansk

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.

PetrKubes97 avatar Mar 04 '24 12:03 PetrKubes97