Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help: Global Error Handler - isQuery /isMutation / meta #4855

Open
AndreaCuneo opened this issue Feb 21, 2025 · 0 comments
Open

Help: Global Error Handler - isQuery /isMutation / meta #4855

AndreaCuneo opened this issue Feb 21, 2025 · 0 comments

Comments

@AndreaCuneo
Copy link

AndreaCuneo commented Feb 21, 2025

I'd like to centralize the handling of errors for queries and to centralize handling of mutations' promises.

I've read docs regarding using a Redux Middleware for Global Errors but I'm seeking a more refined behavior thus asking here for suggestions.

I'm using React and Typescript.

The wanted behaviours are:

  1. On Foreground Query failures, toast an error message. Queries from Polling should be ignored as considered Background.
  2. On Mutations, display a 'loading' toast on start, a success/error toast once promise is completed.
  3. Should be compatible with Retry HoF for baseQuery
  4. Should not apply to other Thunk actions that are not from RTKQ (e.g Slices Thunks)
  5. Can opt-out of these default behaviours with meta flags set either at Hook usage or at Endpoint definition

How can:

  1. Identify Query vs Mutation in either Middleware or BaseQuery
  2. Identify a 'background' vs a first request in a Polling/Refresh scenario
  3. Identify a RTKQ Thunk from non-RTKQ one in Middleware

Any suggestions/pointers would help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant