createAsyncThunkintermediatebuilder.addCase(fetchUser.rejected, (state, action) => {
state.error = action.error.message
state.status = 'failed'
})The rejected handler fires when the async function throws β use action.error.message to display the error to users.
The rejected action fires when the thunk throws an error. Its action.error.message carries the error message string.
Challenge: Handle the rejected case to store the error message in state.error.
userSlice.reducer(undefined, fetchUser.rejected(new Error('not found'), 'req', 1))
// β { error: 'not found', data: null }