Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fetch(`${SERVER_URL}/api/signin`, {
- method: 'POST',
- mode: 'cors',
- body: JSON.stringify({username: email, password:password})})
- .then(response => {
- if (response.status !== 200) {
- debugger;
- const status = response.status;
- const statusText = response.statusText;
- throw("Could not login " + status + " " +statusText);
- /*
- I would like to execute this in order to extract the data.msg from 401 errors
- but my errors get lost in the promise chain.
- response.json()
- .then(data => { throw(data.msg)})
- .catch(() => {throw(status)}
- */
- } else {
- return response.json()}
- })
- .then (data => {
- localStorage.setItem('token', data.access_token);
- dispatch({type: AUTH_USER});
- browserHistory.push('/welcome');
- })
- .catch(errorMsg => {
- dispatch(authError(errorMsg));
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement