My Action.js login function is as follows:
export const auth = (username, password) => {
return dispatch => {
dispatch(authStart());
const config = {
headers: {
'Content-Type': 'application/json'
}
};
const authData = {
username: username,
password: password,
returnSecureToken: true
}
axios.post("http://localhost:4000/scripts/auth/login/", authData, config)
.then(response => {
localStorage.setItem('token', response.data.token);
localStorage.setItem('userId', response.data.user.id);
dispatch(authLoginSuccess(response.data.token, response.data.user.id));
})
.catch(err => {
dispatch(authFail(err))
})
}
}
Django Rest return following detail upon bad credentials:
{
"non_field_errors": [
"Unable to log in with provided credentials."
]
}
But when I am logging the error to console, I don't see any fields like non_field_errors. The err object has the following data as shown by redux dev tools:
Error: Request failed with status code 400
at createError (createError.js:17)
at settle (settle.js:19)
at XMLHttpRequest.handleLoad (xhr.js:60)
How to get this message from API response?