I am making an AJAX call, when it is successful I can read the response as returned by the API, but when there is an error, I only get the error from the server, but not the message
This is my Action code
export const updateUsersAction = (id) => {
return (dispatch) => {
dispatch(beginRequest());
return updateUsers(id)
.then(response => {
dispatch(updateUsersSuccess());
return response.data;
})
.catch(error => {
dispatch(defaultError(error));
throw (error);
});
};
};
The error from the server when id is not found is #400, but there is a specific message
{
"error_message": "The id for this team was not found"
}
How do I read that error_message? Thank you
export const updateUsers = function(id) {
return axios.post(
`/api/update_users/`,
{
id: id
}
);
};
The error JSON can be found on error.response.data, in this case error.response.data.error_message