Skip to content

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

@AndreaCuneo

Description

@AndreaCuneo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions