More robust error handling
This commit is contained in:
parent
c0ac1719a1
commit
88277d2d3f
2 changed files with 13 additions and 6 deletions
|
|
@ -9,12 +9,15 @@ export default (data) => {
|
||||||
|
|
||||||
return axios.post(path, data)
|
return axios.post(path, data)
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
const token = resp.data;
|
if (resp.status === 200) {
|
||||||
localStorage.setItem('auth-token', token);
|
const token = resp.data;
|
||||||
|
localStorage.setItem('auth-token', token);
|
||||||
|
|
||||||
const user = jwtDecode(token);
|
const user = jwtDecode(token);
|
||||||
store.dispatch({ type: 'SET_USER', user: user._doc });
|
store.dispatch({ type: 'SET_USER', user: user._doc });
|
||||||
|
|
||||||
setAuthToken(token);
|
setAuthToken(token);
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,11 @@ const LoginComponent = ({
|
||||||
const submit = (evt) => {
|
const submit = (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
postLogin(state).catch((ex) => {
|
postLogin(state).then((resp) => {
|
||||||
|
if (resp.status !== 200) {
|
||||||
|
setError(`${resp.data}`);
|
||||||
|
}
|
||||||
|
}).catch((ex) => {
|
||||||
setError(`${ex.response.data}`);
|
setError(`${ex.response.data}`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue