I'm trying out Redux-Toolkit and I'm really liking how concise it is but I can't figure out how I'm supposed to read server response status code and dispatch different actions based on that. For instance, I'm sending a sign up request to an API
export const registerRequest = createAsyncThunk(
'register/registerRequest',
async (userInfo: RegisterInfo) => {
const { firstname, lastname, email, password } = userInfo
const { data } = await axios.post('url/users/create', {
firstname,
lastname,
email,
password,
})
return data
}
)
I may receive different types of errors but all of them are handled by a single case in my slice
builder.addCase(registerRequest.rejected, (state, action) => {
state.loading = false
state.error = action.error
})
What is the right way to check for a status code and dispatch corresponding action with Redux-Toolkit ?