Search code examples
reduxreact-reduxredux-toolkitredux-thunk

Redux thunk action is fulfilled when it should have been rejected


I'm dispatching a thunk action that I expect to be rejected, but it's fulfilled instead...

Edit keen-darwin-i9r53l


Solution

  • You are not returning anything from the thunk, therefore the thunk is considered as fulfilled.

    You should return rejectWithValue(e.message) in your catch block.

    } catch (e) {
      errorMessage = `Log from catch block: ${e.message}`;
      return rejectWithValue(e.message);
    }