title: If the axios request fails how do I put the error in the state? Redux toolkit
body: <p>I'm making a simple ecommerce application and I want to show all the products. I use the redux toolkit and according to the documentation I can't find anywhere how to handle the error. This is my product slice:</p>
  <pre><code>import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
  import axios from 'axios';
  
  export const getProducts = createAsyncThunk(
    '/products/getProducts',
    async () =&gt; {
      const { data } = await axios.get('/api/v1/products');
      return data;
    }
  );
  
  const initialState = {
    loading: false,
    products: [],
    product: {},
    error: '',
  };
  
  export const productsSlice = createSlice({
    name: 'products',
    initialState,
    reducers: {},
    extraReducers: {
      [getProducts.pending]: state =&gt; {
        state.loading = true;
      },
      [getProducts.fulfilled]: (state, { payload }) =&gt; {
        state.loading = false;
        state.products = payload;
      },
      [getProducts.rejected]: (state, { payload }) =&gt; {
        state.loading = false;
        state.error = payload;
      },
    },
  });
  
  export const productsReducer = productsSlice.reducer;
  </code></pre>