I am struggling with the code snippet below:
let currentTime:number = (new Date()).getTime();
return this.authenticationService.login(credential).map(data => {
const token = data.token;
const id = data.id;
sessionStorage.setItem('userData', JSON.stringify({currentTime, token, id}));
return JSON.parse(sessionStorage.getItem('userData'));
}).catch(error => {
sessionStorage.setItem('userData', JSON.stringify({currentTime, error}));
return JSON.parse(sessionStorage.getItem('userData'));
});
In this code snippet, both the map
and catch
methods seem to be returning the same code. When I use the map
method and reach the return
statement, everything works fine. However, when I reach the return
in the catch
section, Angular throws an error:
core.js:1598 ERROR TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
. Can anyone help me understand why this is happening?