If your query or mutation happens to throw an error when using fetchBaseQuery, it will be returned in the
error property of the respective hook. The component will re-render when that occurs, and you can show appropriate UI based on the error data if desired.
If you need to access the error or success payload immediately after a mutation, you can chain
Errors with a custom
Whether a response is returned as
error is dictated by the
Ultimately, you can choose whatever library you prefer to use with your
baseQuery, but it's important that you return the correct response format. If you haven't tried
fetchBaseQuery yet, give it a chance! Otherwise, see Customizing Queries for information on how to alter the returned errors.
There are quite a few ways that you can manage your errors, and in some cases, you may want to show a generic toast notification for any async error. Being that RTK Query is built on top of Redux and Redux-Toolkit, you can easily add a middleware to your store for this purpose.
Redux Toolkit has action matching utilities that we can leverage for additional custom behaviors.