rtk-incubator / rtk-query

Data fetching and caching addon for Redux Toolkit
https://redux-toolkit.js.org/rtk-query/overview
MIT License
626 stars 31 forks source link

How can I add a reducer for api/executeQuery/rejected ? #143

Closed kahirokunn closed 3 years ago

kahirokunn commented 3 years ago

I just want to handle all some http status code. 👀 (ex. 403

I couldn't find a way to do this from the current document. Would you like to be able to write code like this?

builder
        .addCase(api.rejected, (state, { meta: { arg, requestId } }) => {
          // do something
        })
msutkowski commented 3 years ago

@kahirokunn There is some information about matchers here as well as here.

You would want to use addMatcher from RTK for this behavior. I can't tell exactly what you want to do from the question, but you can easily sort this out with matchers :)

kahirokunn commented 3 years ago

This is what I've been looking for! Thx!