The thunk appears as follows:
export const registerUser = createAsyncThunk(
"auth/register",
async (userData) => {
try {
const response = await axios.post(REGISTER_URL, userData);
return response.data;
} catch (error) {
// console.log(error.response.data) the output is provided below
throw error.response.data;
}
}
);
Output:
{
"error": "Bad Request",
"message": [
"email should not be empty",
"email must be an email"
],
"statusCode": 400
}
Given this output format, how should I structure the state.error update within the reducer’s .addMatcher()?
.addMatcher(
(action) => action.type.endsWith("/rejected"),
(state, action) => {
state.loading = false;
state.error = ?; // What's the appropriate way to structure the error messages?
}
)