2👍
error.response is undefined. That’s why you’re getting “Cannot read ‘data’ of undefined”.
To protect yourself from this error, I would try the following code…
.catch(error => {
console.log( (error.response || {}).data );
return false;
})
However, the underline reason why you’re not seeing the error when you remove this.store(‘hey’) is a different problem. It seems to be a scope issue. Try removing “this.”
1👍
The problem is the behavior of this
in arrow functions.
If you replace login: (credentials) => {}
with login: function (credentials){}
,
then this.store('hey')
should work.
0👍
Ok guys, thanks to everyone, I found all the errors in my code.
There was two of them:
-
error.response
is not defined (There’s no such property). Proper line should be
console.log(error);
. -
Also, because of arrow-functions behavior (scope issue), the login function couldn’t see my
store
function.
In fact, I got error #2 in second then
statement, so that led my program inside catch
statement, where was error #1.