So are a bunch of non-important things that should go away for clarity, such as all the header munging aside from Authorization
, which isn’t actually being done.
When you write
this.storage.get('token').then((val) => {
throwIntoOcean(val);
});
…I find it helpful to literally think of throwing things into the ocean, like the cliche of a message in a bottle. The stuff inside the then
clause will get executed, but the only place you’ll be able to do things with certainty once it has is in that then
clause.
So, to recap, your code gives a bunch of headers to the request that it doesn’t need (all of them you’re actually setting in time), is manually stringifying postData
(which it shouldn’t do because it ruins automatic content type setting), and doesn’t set the one header you do need to set.
I would suggest this post as an example that you could follow instead.